Skip to content

Give a better error when users make an async fixture non-function-scoped, or use it with a sync test #51

Closed

Description

@njsmith

It would be nice if when Trio mode was activated, this gave an error:

@pytest.fixture
async def my_async_fixture():
    ...

# Notice: not an async test
def test_something(my_async_fixture):
    ...

Obviously we can't do this when trio mode isn't activated, because someone else might be handling the fixture. But when it is, we could give a nice error in theory.

The blocker is that I'm not sure how we're supposed to check the pytest configuration from pytest_fixture_setup...

Also, it would also be nice if we could make it so when Trio mode is activated, this gives an error:

@pytest.fixture(scope="session")
async def whatever():
    ...

This is tricky because if someone does do this, then from pytest_setup_fixture's point of view, it actually won't detect that this fixture should be treated as a trio fixture, because for a session fixture we can't see which tests it will ultimately be used with (and detect that they have @pytest.mark.trio). So this actually ends up being similar to the above case.

(Unless there's some way to ask pytest for a list of all the items that a session-scoped fixture will ultimately be used for, but I don't know of one.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions