Skip to content

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.

code-example

The output looks like this:

terminal-example

Read more
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")