-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError during unit tests: Future attached to a different loop #68
Comments
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! |
- Fix issue in stream/astream endpoint associated with addable types - Have not been able to figure how to run sync unit tests yet with pytest: - fastapi app is async so there's an event loop that's created somewhere - within fastapi sse_starlette also deals with an event loop for the streaming endpoint - This results in a failure when running all unit tests together (sysid/sse-starlette#68)
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:
The text was updated successfully, but these errors were encountered: