Skip to content

Fixture Injection Intentions

Provides intentions to easily convert between explicit fixture parameters and @pytest.mark.usefixtures decorators.

Convert Between Parameter And Decorator Injection

Two intentions help switch between explicit fixture parameters and @pytest.mark.usefixtures.

def test_migrates_database(db):
    assert run_migration()
becomes:
@pytest.mark.usefixtures("db")
def test_migrates_database():
    assert run_migration()

@pytest.mark.usefixtures("db")
def test_migrates_database():
    assert run_migration()
becomes:
def test_migrates_database(db):
    assert run_migration()

Use the decorator form when a fixture is needed only for setup or teardown side effects. Use the parameter form when the test reads the fixture value.