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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.