Skip to content

Parametrizing Fixtures

Fixtures can be parametrized using params=[...]. The elements can be accessed using the special pytest's built-in request fixture.

python
@pytest.fixture(params=["postgres", "mysql", "sqlite"])
def db_driver(request):
    return request.param

def test_database_connection(db_driver):
    # This test runs 3 times, once for each param in the fixture
    assert db_driver in ["postgres", "mysql", "sqlite"]

While pytest.mark.parametrize is used to feed different inputs to a single test, Fixture Parametrization allows you to run all tests that use a specific fixture multiple times.