-
Notifications
You must be signed in to change notification settings - Fork 159
Release 0.13 and 0.14 break standard use of Starlette TestClient #169
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
Comments
Hey @pquentin, thanks for the report. Looks like the Starlette TestClient actually uses asyncio under the hood, and depends on an event loop. So if you encode that dependency into the fixture, like this:
the actual error becomes apparent:
The fix is to make the event_loop fixture be session-scoped too. That's done by overriding it. Here's a working file:
So to me this looks OK on the pytest-asyncio side. |
It's not even a Starlette documentation bug, because Starlette uses a function-scoped fixture in its examples. |
Steps to reproduce
Write
t.py
:Run
pip install pytest pytest-asyncio starlette
and runpytest t.py
.Expected results
All tests pass, including their teardown
Actual results
It was difficult to get to a reproducer, because it's important to have 1/ one test using pytest-asyncio 2/ one test using starlette test client in a fixture. Using such a fixture is actually recommended in the Starlette docs: https://www.starlette.io/config/#a-full-example and was working with pytest-asyncio 0.12.0.
I bisected, and the first bad commit is f97e900.
This is different from #166 because #166 was happening with 0.12.0.
The text was updated successfully, but these errors were encountered: