Skip to content

Commit b0fe041

Browse files
committed
fix test
1 parent 2ea68f2 commit b0fe041

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tests/shared/test_sse.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,25 @@ async def http_client(server, server_url) -> AsyncGenerator[httpx.AsyncClient, N
161161
@pytest.mark.anyio
162162
async def test_raw_sse_connection(http_client: httpx.AsyncClient) -> None:
163163
"""Test the SSE connection establishment simply with an HTTP client."""
164-
async with http_client.stream("GET", "/sse", timeout=5, follow_redirects=True) as response:
165-
assert response.status_code == 200
166-
assert (
167-
response.headers["content-type"]
168-
== "text/event-stream; charset=utf-8"
169-
)
164+
try:
165+
async with http_client.stream("GET", "/sse", timeout=5, follow_redirects=True) as response:
166+
assert response.status_code == 200
167+
assert (
168+
response.headers["content-type"]
169+
== "text/event-stream; charset=utf-8"
170+
)
170171

171-
line_number = 0
172-
async for line in response.aiter_lines():
173-
if line_number == 0:
174-
assert line == "event: endpoint"
175-
elif line_number == 1:
176-
assert line.startswith("data: /messages/?session_id=")
177-
else:
178-
return
179-
line_number += 1
172+
line_number = 0
173+
async for line in response.aiter_lines():
174+
if line_number == 0:
175+
assert line == "event: endpoint"
176+
elif line_number == 1:
177+
assert line.startswith("data: /messages/?session_id=")
178+
else:
179+
return
180+
line_number += 1
181+
except httpx.HTTPStatusError as e:
182+
assert False, f"HTTP error occurred: {e}"
180183

181184

182185
@pytest.mark.anyio

0 commit comments

Comments
 (0)