Skip to content

Figure out how to stop fighting with pytest-asyncio over fixtures #10

@njsmith

Description

@njsmith

As noted in python-trio/trio#27 (comment):

speaking of pytest-asyncio module, it considers any async fixture to be run with asyncio. So if it pytest pytest_fixture_setup is run before pytest-trio one (not sure how pytest decide which module execute first, but that's what happened during my tests), this cause a crash. So right now pytest-asyncio is not compatible with this pytest-trio

Here's my suggestion: since fixtures already have to be explicitly decorated, it's not too onerous to ask the user to also explicitly say which kind of async fixture they want. So instead of writing

from pytest import fixture

@fixture
async def whatever():
    ...

you'd write

from pytest_trio import trio_fixture

@trio_fixture
async def whatever():
   ...

We should probably also continue to install a fixture hook, but make it just detect when someone has accidentally written @fixture async def ... so we can give an error message saying to use @trio_fixture instead.

We should also try to convince the pytest-asyncio folks to switch to this system (CC @Tinche). Especially if we are going to install a fixture hook that will randomly cause their thing to break and tell their users to use @trio_fixture instead :-)

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