Skip to content

loop_scope="package" raises a fixture not found error #1052

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

Closed
NoahStapp opened this issue Jan 27, 2025 · 6 comments
Closed

loop_scope="package" raises a fixture not found error #1052

NoahStapp opened this issue Jan 27, 2025 · 6 comments
Milestone

Comments

@NoahStapp
Copy link

NoahStapp commented Jan 27, 2025

When using loop_scope="package", this fixture defined in my test/asynchronous/conftest.py throws a fatal error on test setup:

@pytest_asyncio.fixture(loop_scope="package", scope="package", autouse=True)
async def test_setup_and_teardown():
    await async_setup()
    yield
    await async_teardown()

# Error:
E       fixture 'test/asynchronous::<event_loop>' not found

Every other loop_scope does not throw this error. Is there an additional step required for package scoped fixtures?

@seifertm
Copy link
Contributor

seifertm commented Feb 8, 2025

@NoahStapp Thanks! This looks like a bug, indeed.

Can you also share the directory layout around the conftest, especially any init.py files?
My assumption is that autouse=True causes the fixture to be injected in tests that don't have a surrounding package.

@seifertm seifertm added the needsinfo Requires additional information from the issue author label Feb 8, 2025
@NoahStapp
Copy link
Author

NoahStapp commented Feb 13, 2025

@NoahStapp Thanks! This looks like a bug, indeed.

Can you also share the directory layout around the conftest, especially any init.py files? My assumption is that autouse=True causes the fixture to be injected in tests that don't have a surrounding package.

Sure, here's the layout:

test
├── __init__.py
├── asynchronous
│   ├── __init__.py
│   ├── conftest.py
│   ├── # asynchronous test files...
├── conftest.py
├── # synchronous test files...

We use pytest-asyncio for our asynchronous test suite and pytest for our synchronous test suite.

@seifertm seifertm removed the needsinfo Requires additional information from the issue author label Mar 25, 2025
@seifertm
Copy link
Contributor

Slowly getting back to this…
I tried to reproduce the issue a few weeks ago, but I didn't have any success.

@NoahStapp Could you provide a minimal reproducible example that exhibits the error? For example, a bunch of files for me to copy to my development environment. This is the fastest way to get help.

@seifertm
Copy link
Contributor

@NoahStapp The pytest-asyncio pre-release v1.0.0a1 introduces significant changes to the way scoped event loops are handled. Could you retest with pytest-asyncio==1.0.0a1 and see if this resolves the error?

@seifertm seifertm added the needsinfo Requires additional information from the issue author label May 14, 2025
@seifertm seifertm added this to the v1.0 milestone May 14, 2025
@b-kamphorst
Copy link

b-kamphorst commented May 14, 2025

I just bumped into the same issue (don't have a minimal example yet; fear it is quite some work to extract that), and the tests run fine with pytest-asyncio==1.0.0a1!

Edit: I experienced the issue with pytest-asyncio==0.26.0.

@seifertm
Copy link
Contributor

Thanks @b-kamphorst !

Since this seems to be fixed with v1.0.0a1, let's close the issue. I'm happy to reopen, if there's any other indication.

@seifertm seifertm removed the needsinfo Requires additional information from the issue author label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants