-
Notifications
You must be signed in to change notification settings - Fork 161
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
How to use the same event loop for fixtures and tests? #947
Comments
any update on how to solve this? as of now the only solution I've found is to override in @pytest.fixture(scope="module")
def event_loop():
loop = asyncio.get_event_loop()
yield loop
loop.close() |
@WisdomPill To run all fixtures in the same event loop, you can set asyncio_default_fixture_loop_scope. This how-to guide describes a way to run all tests in the same loop. |
@seifertm the suggested solution only makes all fixtures to share the same event loop, tests get separate instances (or an instance if the session test scope is used). What was the reason to deprecate the |
@domartynov The next release will also add a similar option for tests (#793) |
Python
3.11.2
pytest-asyncio
0.24
(I've tried rolling back to 0.21, but no luck)I'm writing integration tests for a library we publish that uses asyncio.
We have async fixtures that establish a
Session
(which is really a gRPC connection) to a backend, obtain a structure to dispatch various operations. This structure is then passed to the each of the async test functions.If I run tests individually, everything is fine. However, if I run all of the tests in a particular test file, the first test passes and all subsequent tests fail in a fashion similar to:
I've tried setting the
loop_scope
tosession
for each test without any luck.I've tried using
conftest.py
approach as outlined here but this approach fails with:I'm running out of ideas on how to approach/further diagnose this (I'm primarily a Java developer working on Python stuff on the side, so bear with me). Any pointers on how I can tackle getting to the bottom of this?
Some sample code from our tests:
The text was updated successfully, but these errors were encountered: