@@ -150,42 +150,31 @@ def server(server_port: int) -> Generator[None, None, None]:
150150 print ("server process failed to terminate" )
151151
152152
153- @pytest .fixture ()
154- async def http_client (server , server_url ) -> AsyncGenerator [httpx .AsyncClient , None ]:
155- """Create test client"""
156- async with httpx .AsyncClient (base_url = server_url ) as client :
157- yield client
158-
159153
160154@pytest .mark .anyio
161- async def test_raw_sse_connection (http_client : httpx . AsyncClient ) -> None :
155+ async def test_raw_sse_connection (server , server_url ) -> None :
162156 """Test the SSE connection establishment simply with an HTTP client."""
163157 try :
164- async with anyio .create_task_group ():
165-
166- async def connection_test () -> None :
167- async with http_client .stream ("GET" , "/sse" ) as response :
168- assert response .status_code == 200
169- assert (
170- response .headers ["content-type" ]
171- == "text/event-stream; charset=utf-8"
172- )
173-
174- line_number = 0
175- async for line in response .aiter_lines ():
176- if line_number == 0 :
177- assert line == "event: endpoint"
178- elif line_number == 1 :
179- assert line .startswith ("data: /messages/?session_id=" )
180- else :
181- return
182- line_number += 1
183-
184- # Add timeout to prevent test from hanging if it fails
185- with anyio .fail_after (3 ):
186- await connection_test ()
158+ async with httpx .AsyncClient (base_url = server_url ) as http_client :
159+ async with http_client .stream ("GET" , "/sse" ) as response :
160+ assert response .status_code == 200
161+ assert (
162+ response .headers ["content-type" ]
163+ == "text/event-stream; charset=utf-8"
164+ )
165+
166+ line_number = 0
167+ async for line in response .aiter_lines ():
168+ if line_number == 0 :
169+ assert line == "event: endpoint"
170+ elif line_number == 1 :
171+ assert line .startswith ("data: /messages/?session_id=" )
172+ else :
173+ return
174+ line_number += 1
175+
187176 except Exception as e :
188- pytest .fail (f"HTTP error occurred: { e } " )
177+ pytest .fail (f"{ e } " )
189178
190179
191180@pytest .mark .anyio
0 commit comments