-
Notifications
You must be signed in to change notification settings - Fork 149
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
Warning when defining session scoped event_loop fixture: "pytest-asyncio will close the event loop for you, but future versions of the library will no longer do so." #531
Comments
Thanks for the report and the great reproducer! The intention of the warning is to point out flawed event loop handling. With the deprecation of Unfortunately, the example seems to suffer from exactly this problem. When running the code with
Since we can only have one event loop [0], the function-scoped fixture will close the session-scoped event loop prematurely. If you move the
I think the warning does what it's supposed to. I also agree that it's probably a good idea to adjust the docs accordingly. In your particular case, you can probably achieve your goal by using a module-scoped fixture for the integration tests:
[0] technically it's one loop per thread, but we're not running in multiple threads |
@seifertm yeah that all makes sense, and aligns with what I was guessing might be happening. In my case I just moved the fixture to the root like I mentioned in my original post. Although I did test and see that a module scope fixture worked too. From what it's sounding like, maybe it's as simple as some doc improvements... (and/or improvements to the warning message) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
The example for overriding event loop scopes now uses a module scope rather than a session scope. Due to the constraint that event_loop fixture scopes should not overlap, a session-scoped fixture is usually not that helpful. Addresses pytest-dev#531 Signed-off-by: Michael Seifert <[email protected]>
…nal possible cause. Closes pytest-dev#531 Signed-off-by: Michael Seifert <[email protected]>
The example for overriding event loop scopes now uses a module scope rather than a session scope. Due to the constraint that event_loop fixture scopes should not overlap, a session-scoped fixture is usually not that helpful. Addresses #531 Signed-off-by: Michael Seifert <[email protected]>
…nal possible cause. Closes #531 Signed-off-by: Michael Seifert <[email protected]>
This warning was recently added in #510
I am getting this warning with the following test case. Essentially, we have two directories with async tests. One directory defines a session-scoped event_loop, and the other one doesn't do anything with event_loop.
File
tests/integration/conftest.py
:File
tests/integration/test_integration.py
:File
tests/unit/test_unit.py
:Also set the pytest configuration in
pyproject.toml
as follows:Now run
pytest
from the root directory:I found that if I move the event_loop fixture to a root
tests/conftest.py
, then I no longer get the warning. I am not sure if that is an intentional limitation (or feature?), or if it is a bug.If the limitation is intentional, may I suggest a documentation improvement? The section at https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures.html#event-loop talks at length about making your own session-scoped event_loop fixture. But it does not talk about this issue, and it was a little time-consuming to track down in my project.
The text was updated successfully, but these errors were encountered: