pytest decorator for parametrizing test cases in a dict-way. It is an alternative for the pytest.mark.parametrize.
Decorate test function with test cases defined as a dictionary.
import pytest
from pytest_parametrize import parametrize
@parametrize(
{
"test-case-1": {"a": 1, "b": 2, "c": 3},
"test-case-2": {"a": 2, "b": 3, "c": 5},
"test-case-3": [
{"a": 3, "b": 5, "c": 8},
{"a": 5, "b": 8, "c": 13},
{"a": 8, "b": 13, "c": 21},
{"a": 0, "b": 0, "c": 1, "marks": pytest.mark.xfail},
],
},
)
def test_something(a, b, c):
assert a + b == c
from pytest_parametrize import parametrize
@parametrize(
{
"a=1": {"a": 1},
"a=2": {"a": 2},
}
)
@parametrize(
{
"b=1": {"b": 1},
"b=2": {"b": 2},
}
)
def test_parametrize__when_complex_structure(a: int, b: int):
assert a * b > 0
Decorator takes dict, which:
- keys define names of the test cases, and
- values define named arguments in dict manner (or list of such dicts), which are passed to the decorated test function.
pip install pytest-parametrize
poetry add pytest-parametrize
pytest -vvv tests --cov=pytest_parametrize