-
Notifications
You must be signed in to change notification settings - Fork 160
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
Teardown error: "attached to a different loop" with even_loop module scope fixture #162
Comments
I have a similar problem that async fixtures are somehow attached to a different loop than the pytest |
After some debugging, side_effect of get_event_loop is causing a change of loop. It seems safer the previous method used in 0.10.0 that recovers the loop created in event_loop fixture. See details below
then there is a problem with an implicit side effect of asyncio.get_event_loop. See extracted below:
As _get_running_loop() is still None, then self.set_event_loop(self.new_event_loop()), is creating and setting a 2º event_loop (different from the one created at the event_loop fixture) Hope this can help. If anything else is needed please let me know. |
Thanks for the analysis, I guess I need to dive deeper into this to really understand it. Can you think of a way of solving this? |
I can try to do my best to find a solution and prepare a pull request, if you agree on it. Just one question I don´t understand block under if on line 54:
This block is under the condition of being asyncio in request.keyworks:
Several options:
I would appreciate if anyone can clarify on the right expected behaviour Thanks in advance. |
Hi Don´t hesitate to contact me for any additional support. |
I can no longer reproduce the error of the OP as of pytest-asyncio 0.21.1. Hence, I'll mark this issue as resolved. |
I'm getting the same error message which occurs on teardown ("..attached to a different loop..") for version 0.23.2. When downgrading to version 0.21.1 everything is fine. |
@poppyi-domain Pytest-asyncio v0.23 supports running tests in different event loops. There's a loop for each level of the test suite (session, package, module, class, function). However, pytest-asyncio wrongly assumes that the scope of an async fixture is the same as the scope of the event loop in which the fixture runs. This essentially makes it impossible to have a session-scoped fixture that runs in the same loop as a function-scoped test. See #706. If v0.23 causes trouble for you, I suggest sticking to pytest-asyncio v0.21, until the issue is resolved. |
I'm working on python/pytest/asyncio since beginning of this year, and when updating pytest-asyncio (from 0.10.0 to 0.12.0) then some previous working tests started to fail.
I have created following minimal example (isolated from a more complex solution) that always fails at teardown.
Can you please let me know if you can reproduce it, and your kind feedback about this potential issue.
Don´t hesitate to ask for any additional information or test on my side.
BR
Angel Luis
Additional info
Versions used to reproduce are:
Note: Minimal Example works with pytest-asyncio 0.10.0.
Minimal example is the following
When I run the test I get the following console output:
Unexpectedly either of the following changes, made the test to pass:
a) Change fixture to a lower level scope (class or function):
b) Embed the test inside a class:
c) Or change finalizer to call get_event_loop (instead of using event_loop from fixture)
The text was updated successfully, but these errors were encountered: