@@ -148,9 +148,9 @@ async def mock_receive(): # pragma: no cover
148148 # Give other tasks a chance to run. This is important for the finally block.
149149 await anyio .sleep (0.01 )
150150
151- assert session_id not in manager . _server_instances , (
152- "Session ID should be removed from _server_instances after graceful exit"
153- )
151+ assert (
152+ session_id not in manager . _server_instances
153+ ), "Session ID should be removed from _server_instances after graceful exit"
154154 assert not manager ._server_instances , "No sessions should be tracked after the only session exits gracefully"
155155
156156
@@ -201,9 +201,9 @@ async def mock_receive(): # pragma: no cover
201201 # Give other tasks a chance to run to ensure the finally block executes
202202 await anyio .sleep (0.01 )
203203
204- assert session_id not in manager . _server_instances , (
205- "Session ID should be removed from _server_instances after an exception"
206- )
204+ assert (
205+ session_id not in manager . _server_instances
206+ ), "Session ID should be removed from _server_instances after an exception"
207207 assert not manager ._server_instances , "No sessions should be tracked after the only session crashes"
208208
209209
@@ -318,8 +318,21 @@ async def mock_receive():
318318 assert error_data ["error" ]["message" ] == "Session not found"
319319
320320
321+ @pytest .fixture
322+ def reset_sse_app_status ():
323+ # Needed for tests with sse-starlette < 3
324+ # https://github.com/sysid/sse-starlette/issues/59
325+ # https://github.com/sysid/sse-starlette/blob/v3.2.0/README.md#testing
326+
327+ from sse_starlette .sse import AppStatus
328+
329+ AppStatus .should_exit_event = None
330+ yield
331+ AppStatus .should_exit_event = None
332+
333+
321334@pytest .mark .anyio
322- async def test_e2e_streamable_http_server_cleanup ():
335+ async def test_e2e_streamable_http_server_cleanup (reset_sse_app_status : None ):
323336 host = "testserver"
324337 app = Server ("test-server" )
325338
0 commit comments