pytest
Parametrizing Fixtures
Fixtures can be parametrized using params=[...]. The elements can be accessed using the special pytest's built-in request fixture.
@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.
Extending and Renaming
Introduction
pytest provides several useful built-in fixtures. Below are some of the most commonly used ones, explained at a high level. For a complete list of all pytest built-in fixtures, see the official reference. If you want to explore any specific fixture in more depth, refer to its dedicated documentation page.
