Skip to content

pytest-anyio should raise error if sync test relies on async fixture #789

@jakkdl

Description

@jakkdl

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

Sync test function attempting to use async fixture fails silently. pytest-trio will raise a RuntimeError in this instance.

The one possible downside is that this will break users who have async autouse fixtures in the same file where they have sync tests. But this restriction probably isn't too onerous, and may catch bugs as well.

Use case

Catch bugs and align behavior with pytest-trio

import pytest

pytestmark = pytest.mark.anyio

@pytest.fixture(autouse=True)
async def async_fixture():
    assert False
    yield


def test_1(async_fixture):
    assert True

def test_2():
    assert True

will pass, but probably shouldn't

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions