Parametrization

pytest
Author

Imad Dabbura

Published

August 22, 2023

Test parametrization allows us to avoid redundant code by writing one test function/fixture that tries to test the same logic with different values/parameters. pytest will generate tests for us by calling the same test function/fixture passing different combination of parameters each time. Example:

pytest.mark.parametrize(
    ["param_name1", "param_name2", "param_name3"],
        [
        (1, "a", 3),
        (1, "x", 0),
        (5, "d", 100),
    ]
)
def test_func(param_name1, param_name2, param_name3):
    pass