-
Notifications
You must be signed in to change notification settings - Fork 152
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
event_loop
not found for multiple test modules
#862
Comments
Same issue for me, I have the same Logs:
For somehow the fixture |
Starting from pytest-asyncio v0.23, every level of the pytest test collection hierarchy has its own asyncio event loop. By default, tests marked with Unfortunately, pytest-asyncio v0.23 falsely assumes that the caching scope and event loop scope for async fixtures are the same. In your example, this means that You'll want to adjust your tests to use @pytest.mark.asyncio(scope="module")
async def test_func(foo):
... for everything to run in the same event loop. Is this something that you can do in your codebase (not the example)? |
Closing this issue, because I don't have enough information to take any action. Feel free to continue adding comments, though. |
I have the same issue and would like the issue re-opened. Adding
import pytest_asyncio
@pytest_asyncio.fixture(scope="module")
async def foo():
yield "a value"
import pytest
@pytest.mark.asyncio(scope="module")
async def test_func(foo):
print("test_1 test_func", foo)
import pytest
@pytest.mark.asyncio(scope="module")
async def test_func(foo):
print("test_2 test_func", foo) Test run output:
|
Thanks for the reproducer @cstruct ! This seems to be related to the fixture processing code in pytest-asyncio. Async fixtures are processed at collection time. It looks like foo references the event loop of test_1.py, even though it's being re-evaluated in test_2.py. At that point, the event loop of test_1.py is no longer available. See also #668 |
Thank you for the quick response! 🤗 |
Caching of fixture preprocessing is now also keyed by event loop id, sync fixtures can be processed if they are wrapping a async fixture, each async fixture has a mapping from root scope names to fixture id that is now used to dynamically get the event loop fixture. This fixes pytest-dev#862.
Caching of fixture preprocessing is now also keyed by event loop id, sync fixtures can be processed if they are wrapping a async fixture, each async fixture has a mapping from root scope names to fixture id that is now used to dynamically get the event loop fixture. This fixes #862.
…n reused in other modules. Async fixture synchronizers now choose the event loop for the async fixutre at runtime rather than relying on collection-time information. This fixes pytest-dev#862.
…n reused in other modules. Async fixture synchronizers now choose the event loop for the async fixutre at runtime rather than relying on collection-time information. This fixes #862.
The fix is available in the pytest-async v0.24.0a1 pre-release. |
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
I just want to use module scope fixture but I get an error:
[environment]
python==3.10.14
pytest==8.2.2
pytest-asyncio==0.23.7
[Directory]
tests/conftest.py
:tests/test_1.py
:tests/test_2.py
:[error]
according to the document Decorators:
I add
event_loop
fixture inconftest.py
:But this error is still there.
The text was updated successfully, but these errors were encountered: