Closed hinzundcode closed 11 months ago
I don't think this is sse-starlette related. It is sometime a bit tricky to have correct event-loop handling in combination with pytest.
If you face the issue outside pytest in regular app, please reopen.
I had the same issue, only with SSE, so what I had to was for any tests involving SSEs I launched the webapp in a subprocess and made calls using a real http client (not the test client).
@hinzundcode did you ever get to the bottom of this? I seem to be facing the same issue, thanks!
Started a discussion in FastAPI in case anyone's interested! https://github.com/tiangolo/fastapi/discussions/10518
I tried to write pytest testcases for a FastAPI route that returns an event source/stream. The first test always succeedes, but the second test, despite identical content, consistently runs into an error:
RuntimeError: Task ... got Future ... attached to a different loop
. I'm not sure if the error is related to sse_starlette, fastapi, httpx or pytest-asyncio. I'll try it here first.Here is a minimal example that can be used to reproduce the issue:
Versions used:
sse-starlette 1.6.1 fastapi 0.101.0 httpx 0.24.1 pytest 7.4.0 pytest-asyncio 0.21.1
My pytest config looks like this:
And here is the full error log: