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

Open
NoahStapp opened this issue Jan 27, 2025 · 3 comments
Open

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

NoahStapp opened this issue Jan 27, 2025 · 3 comments

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.

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

2 participants