Skip to content
Sarj Code Standards

prefer-single-parametrize-contract

Prefer one explicit pytest parameter contract; preserve Cartesian products compactly.

Why

Stacked static axes scatter the test input contract across decorators. One named contract can keep their Cartesian product compact without repeating literal rows.

Fix

Use one tuple of argument names and list(itertools.product(...)) for independent static axes. Retain pytest's innermost-to-outermost axis order and verify collected IDs, case count and behavior. Do not expand the product into a repetitive literal table.

Examples

Before — flagged Reject the anti-pattern
tests/test_value.py
import pytest
@pytest.mark.parametrize("mode", ["a", "b"])
@pytest.mark.parametrize("kind", [1, 2])
def test_value(kind, mode):
assert kind in (1, 2) and mode in ("a", "b")
After — preferred Accept the preferred alternative
tests/test_value.py
import pytest
from itertools import product
@pytest.mark.parametrize(("kind", "mode"), list(product([1, 2], ["a", "b"])))
def test_value(kind, mode):
assert kind in (1, 2) and mode in ("a", "b")