Skip to content

PY-TEST0018 · module_generated_parametrization_count

Count parametrizations driven by a module-generated case collection.

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

Find a collected test whose pytest.mark.parametrize case source is a module-level list, set, or generator comprehension. Unlike a short literal table, its item count grows with repository data and silently multiplies the collected suite. Report each generated parametrization once.

Each finding points to the test and counts the generated parametrization decorators it carries. The value is their sum per module. This rule measures the unbounded collection mechanism rather than guessing a case count from source text.

Literal case tables, static ranges, fixture parametrization, and dynamically returned iterables abstain. Keep a generated parametrization only when every case needs its own selection identity, marks, retry history, or parallel scheduling. Repository-wide structural invariants should normally aggregate their failures inside one test.

Bad

Parametrizing one invariant over every discovered `rule module` is reported.
Good

Parametrizing three named protocol modes from a literal tuple is not.

  • Cites “pytest documentation”, parametrization. Open reference
  • Cites “xUnit Test Patterns”, test code duplication