Skip to content

PY-TEST0013 · manual_literal_test_case_loop_count

Count manual literal case loops that should use Pytest parametrization.

This is a deterministic rule for python. Read its implementation.

Inspect tests collected by Pytest’s default Python conventions. Report a for loop when it iterates over at least minimum_cases literal list, tuple, or set entries and owns an assertion. The default requires three cases. Parametrization gives each case an independent collection identity, failure report, mark surface, and selection target.

Each finding identifies the test and loop range and records the number of manual cases. The rule does not rewrite case IDs or infer fixture parameters. The value is the number of manual literal case loops.

Dynamic iterables, loops without assertions, and fewer than three cases abstain. Keep a loop when iteration order or accumulated state is the behavior under test. Use Hypothesis instead when the cases represent a broad generated domain rather than a short example table.

def test_normalize():
for raw in ("A", "B", "C"):
assert normalize(raw).islower()
@pytest.mark.parametrize("raw", ["A", "B", "C"])
def test_normalize(raw):
assert normalize(raw).islower()