Improve parametrize error for invalid tuple-style values#14629
Open
itscloud0 wants to merge 1 commit into
Open
Improve parametrize error for invalid tuple-style values#14629itscloud0 wants to merge 1 commit into
itscloud0 wants to merge 1 commit into
Conversation
3dd1e5e to
ce198fe
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
parametrizeargument names receive an invalid scalar parameter set.Previously,
@pytest.mark.parametrize("x,", [None, "foo", "bar"])crashed while formatting the validation error because pytest calledlen()onNone. 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 offoo.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 -quv run --python /opt/homebrew/bin/python3.12 --extra dev --with-editable . python -m pytest testing/python/metafunc.py -quvx pre-commit run --files src/_pytest/mark/structures.py testing/python/metafunc.py AUTHORS changelog/14619.bugfix.rstNotes
Full test suite was not run locally; this change is covered by the focused parametrization tests and the full
testing/python/metafunc.pymodule.AI tooling was used while preparing this patch, and the commit includes a
Co-authored-bytrailer for attribution.