parametrized test

One test function run many times with different data, each run reported as a separate test case.

In more detail

@pytest.mark.parametrize takes the parameter names as one string and a list of tuples, one per case. Each case can be rerun alone, and ids= gives each case a readable name for reports. Parametrize the data, not the behaviour: if the body needs an if statement to cope, you have two tests.

Example

@pytest.mark.parametrize(
    "price, expected",
    [(1000, 900), (999, 899)],
    ids=["round", "off-by-a-penny"],
)

Related terms

Taught in

References