Skip to content

opaque-parametrize-case-needs-id

Opaque static pytest parameter cases rely on argument-name-and-index fallback IDs.

Why

Fallback IDs such as payload0 are hard to diagnose and silently change when the table is reordered.

Fix

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