This rule raises an issue when a pytest mark is applied where it has no effect: any @pytest.mark.* on a @pytest.fixture,
or @pytest.mark.usefixtures() with no fixture names.
Pytest applies marks to tests, classes, and modules. Marks on fixtures are ignored, and an empty @pytest.mark.usefixtures() does
nothing.
Decorating a fixture with @pytest.mark.asyncio, @pytest.mark.usefixtures(…), or any other @pytest.mark.*
does not change how the fixture runs or which tests use it:
@pytest.mark.asyncio # Ignored: fixtures are not tests
@pytest.fixture
async def db():
return await connect()
@pytest.mark.usefixtures("db") # Ignored on fixtures
@pytest.fixture
def client(db):
return Client(db)
@pytest.mark.slow # Ignored on fixtures
@pytest.fixture
def cache():
return {}
Maintainers may assume the mark selects the fixture, runs it asynchronously, or injects other fixtures. None of that happens.
To depend on another fixture, declare it as a parameter. For async fixtures, use an async fixture function; pytest-asyncio does not require
@pytest.mark.asyncio on the fixture itself.
@pytest.mark.usefixtures() with no names is a no-op:
@pytest.mark.usefixtures() # No fixtures requested
def test_ping():
assert ping() == "pong"
Either pass the fixture names that should be activated, or remove the decorator.
Useless marks look intentional but change nothing. Teams may believe fixtures are skipped, marked slow, run under asyncio, or wired via
usefixtures, while the suite behaves differently than expected.
Remove marks from fixtures. Request other fixtures as parameters instead of @pytest.mark.usefixtures on the fixture. For empty
@pytest.mark.usefixtures(), either supply fixture names or delete the decorator.
import pytest
@pytest.mark.asyncio # Noncompliant
@pytest.fixture
async def db():
return await connect()
@pytest.mark.usefixtures("db") # Noncompliant
@pytest.fixture
def client(db):
return Client(db)
@pytest.mark.slow # Noncompliant
@pytest.fixture
def cache():
return {}
import pytest
@pytest.fixture
async def db():
return await connect()
@pytest.fixture
def client(db):
return Client(db)
@pytest.fixture
def cache():
return {}
import pytest
@pytest.mark.usefixtures() # Noncompliant
def test_ping():
assert ping() == "pong"
def test_ping():
assert ping() == "pong"