PY-TEST0003 · parametrization_candidate_group_count
Count safe sibling-test groups that differ only in literal values.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Compare direct sibling test functions within the same module or class. Preserve the callable
kind, fixture parameter names, argument defaults, annotations, decorators, marks, control-flow
nodes, operators, and call targets. Replace body literals with typed slots, then report a group
only when at least minimum_cases tests have the same remaining syntax and every case has a
distinct literal vector. The defaults set minimum_cases to three and maximum_cases to nine.
Evidence
Section titled “Evidence”Each finding spans the candidate group, names every test, and measures both case count and the number of literal positions that vary. The rule reports an opportunity and does not rewrite test names or invent parameter IDs. The value is the number of qualifying sibling groups rather than the number of tests in them.
Exceptions
Section titled “Exceptions”Already parametrized tests, tests with docstring scenarios, exception contexts, explicit try
or raise statements, external assignment, and common filesystem or monkeypatch side effects
abstain. Different fixtures, marks, control flow, call targets, or literal types form different
shapes. Exact duplicate bodies are not parametrization candidates. Ruff PT006, PT007, and PT014
remain responsible for parametrization syntax and duplicate existing cases. Ten or more
homogeneous examples belong to PY-TEST0017, which asks for one generated property instead.
Examples
Section titled “Examples”def test_status_ok(client): assert client.get("/ok").status_code == 200
def test_status_missing(client): assert client.get("/missing").status_code == 404
def test_status_denied(client): assert client.get("/denied").status_code == 403@pytest.mark.parametrize( ("path", "status"), [("/ok", 200), ("/missing", 404), ("/denied", 403)],)def test_status(client, path, status): assert client.get(path).status_code == statusReferences
Section titled “References”- Cites “pytest documentation”, parametrizing fixtures and test functions. Open reference
- Cites “pytest documentation”, parametrization examples. Open reference
- Cites Ruff PT014 pytest-duplicate-parametrize-test-cases. Open reference