Skip to content

Improve parametrize error for invalid tuple-style values#14629

Open
itscloud0 wants to merge 1 commit into
pytest-dev:mainfrom
itscloud0:fix-14619-parametrize-error-message
Open

Improve parametrize error for invalid tuple-style values#14629
itscloud0 wants to merge 1 commit into
pytest-dev:mainfrom
itscloud0:fix-14619-parametrize-error-message

Conversation

@itscloud0

Copy link
Copy Markdown

Closes #14619.

Summary

This improves the collection error raised when tuple-style parametrize argument names receive an invalid scalar parameter set.

Previously, @pytest.mark.parametrize("x,", [None, "foo", "bar"]) crashed while formatting the validation error because pytest called len() on None. The updated validation reports the bad parameter set index directly instead.

It also makes the existing string mismatch case clearer by displaying the string as the sequence pytest counted, e.g. ['f', 'o', 'o'], instead of foo.

Test plan

  • uv run --python /opt/homebrew/bin/python3.12 --extra dev --with-editable . python -m pytest testing/python/metafunc.py::TestMetafunc::test_parametrize_trailing_comma_scalar_parameter_set testing/python/metafunc.py::TestMetafunc::test_parametrize_string_parameter_set_error_shows_sequence -q
  • uv run --python /opt/homebrew/bin/python3.12 --extra dev --with-editable . python -m pytest testing/python/metafunc.py -q
  • uvx pre-commit run --files src/_pytest/mark/structures.py testing/python/metafunc.py AUTHORS changelog/14619.bugfix.rst

Notes

Full test suite was not run locally; this change is covered by the focused parametrization tests and the full testing/python/metafunc.py module.

AI tooling was used while preparing this patch, and the commit includes a Co-authored-by trailer for attribution.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 19, 2026
@itscloud0 itscloud0 marked this pull request as ready for review June 19, 2026 21:10
@itscloud0 itscloud0 force-pushed the fix-14619-parametrize-error-message branch from 3dd1e5e to ce198fe Compare June 20, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spurious comma in parametrize causes obfuscated crash

1 participant