Skip to content
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

pytest-asyncio 0.23 doesn't allow class-scoped fixtures outside of class definition #829

Open
av223119 opened this issue May 2, 2024 · 1 comment

Comments

@av223119
Copy link

av223119 commented May 2, 2024

It appears that the pytest-asyncio 0.23 broke class-scoped fixtures defined outside of the class. Namely, I used to have the following setup:

conftest.py:

@pytest_asyncio.fixture(scope="class")
async def run_important_program_in_class() -> AsyncGenerator[ImportantProgram, None]:
    """runs one Program instance per test class"""
    async with run_important_program(cfg=generate_cfg()) as p:
        yield p

and then the test classes used
@pytest.mark.usefixtures("run_important_program_in_class")

however with upgrade to 0.23, now the following error being reported:

ERROR my_example_test.py - _pytest.config.exceptions.UsageError: my_example_test.py is marked to be run i
n an event loop with scope class, but is not part of any class

The error disappears of the fixture is moved to the class definition, like this:

Class TestSomeStuff:
    @pytest_asyncio.fixture(scope="class")
    async def run_important_program_in_class() -> AsyncGenerator[ImportantProgram, None]:
        async with run_important_program(cfg=generate_cfg()) as p:
            yield p

But this approach leads to significant code duplication

@av223119
Copy link
Author

av223119 commented May 2, 2024

Looks like the root cause of this is #706

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

1 participant