Skip to content

Pytest parametrize positional keyword-only inspection

Reports positional indirect, ids, and scope arguments passed to pytest.mark.parametrize when the file's interpreter uses pytest 9.2 or later. The quick-fix converts the optional positional arguments together, preserving valid Python syntax and each value.

# Before
@pytest.mark.parametrize("value", [1], True, ["one"], "module")
def test_value(value):
    pass

# After applying the fix
@pytest.mark.parametrize("value", [1], indirect=True, ids=["one"], scope="module")
def test_value(value):
    pass

The inspection stays silent for older or unknown pytest versions and skips starred arguments whose positional offsets cannot be determined statically. Each module uses its own interpreter's pytest version. Disable the inspection under Settings → BetterPy → Testing / Pytest → Parametrize.

Long string parameter IDs

On pytest 9.2 and later, BetterPy conservatively stops predicting an entire parameter ID set when a default string or bytes ID exceeds 100 characters. The winning pytest config's parametrize_long_str_id_strategy = legacy keeps full IDs. The default short, sha256, disallow, and unknown strategies fall back to collected IDs rather than guessing. Explicit ids=[...] and pytest.param(id=...) remain supported. Unknown pytest versions use the same conservative prediction; pytest versions before 9.2 retain the existing IDs.