11 - pytest-cases
The core idea behind pytest-cases is to separate test code from test cases. One of its cool features is the possibility to use fixtures inside parametrize. Additionally, it enables familiar syntax for parametrizing fixtures.
The output looks like this:
Read more
- pytest-cases docs: https://smarie.github.io/python-pytest-cases/
- pytest-cases GitHub repo: https://github.com/smarie/python-pytest-cases/
The code
from pytest_cases import fixture, parametrize
@fixture
def fixture1() -> str:
return "foo"
@fixture
@parametrize("value", ["bar", "baz"])
def fixture2(value: str) -> str:
return value
@parametrize("value", [fixture1, fixture2])
def test_just_a_dummy_example(value: str) -> None:
assert value in ("foo", "bar", "baz")