Skip to content
Sarj Code Standards

opaque-parametrize-case-needs-id

Opaque static pytest parameter cases lack table-local semantic IDs.

Why

Without a semantic naming owner, fallback IDs such as payload0 are hard to diagnose and silently change when the table is reordered.

Fix

Check the owning pytest_make_parametrize_id hook before adding IDs; reuse an existing semantic naming owner. Otherwise give each opaque row a semantic pytest.param(..., id=...), or use a semantic callable ids= when one mapping applies to the entire table.

Examples

Before — flagged Dictionary cases receive generated names
tests/test_handler.py
import pytest
@pytest.mark.parametrize("payload", [{}, {"status": "invalid"}])
def test_handler(payload):
assert handle(payload)
After — preferred Dictionary cases have stable names
tests/test_handler.py
import pytest
@pytest.mark.parametrize(
"payload",
[
pytest.param({}, id="empty-payload"),
pytest.param({"status": "invalid"}, id="invalid-status"),
],
)
def test_handler(payload):
assert handle(payload)

Formerly: parametrize-case-needs-id