Skip to content

Python · testing

opaque-parametrize-case-needs-id

python:opaque-parametrize-case-needs-id

Opaque `parametrize` case with no `ids=`/`id=` — the failing case reports as `case0`.

Code
SARJ042
Default
error
Fix
none
Languages
python

Why

Generated case numbers are hard to diagnose and silently change when the parameter table is reordered.

Fix

Add `ids=` to the decorator or give each opaque `pytest.param` an explicit `id=`.

Before / after

Executed by this rule’s unit tests.

Before

Dictionary cases receive generated names

tests/test_handler.py · focus
import pytest

@pytest.mark.parametrize("payload", [{"a": 1}, {"a": 2}])
def test_handler(payload):
    assert handle(payload)

After

Dictionary cases have stable names

tests/test_handler.py · focus
import pytest

@pytest.mark.parametrize("payload", [{"a": 1}, {"a": 2}], ids=["first", "second"])
def test_handler(payload):
    assert handle(payload)

Limits

  • Only static list or tuple parameter tables in test files are analyzed.
  • Cases with a pytest-readable scalar column or an explicit ID are allowed.

Formerly: parametrize-case-needs-id