Improve parametrize error for scalar parameter sets#14621
Open
mike-lmctl wants to merge 2 commits into
Open
Conversation
Tuple-style parametrization expects each parameter set to be a sequence of values. When a scalar like None was passed, pytest crashed while trying to format the validation error because it called len() on the scalar. Report a normal collection error instead, pointing at the offending test. Tested: PYTHONPATH=src python3 -m pytest testing/test_mark.py::test_parametrized_collect_with_non_sequence_values testing/test_mark.py::test_parametrized_collect_with_wrong_args -q Tested: PYTHONPATH=src python3 -m pytest testing/test_mark.py -q Tested: git diff --check -- src/_pytest/mark/structures.py testing/test_mark.py changelog/14619.bugfix.rst AUTHORS Tested: python3 -m py_compile src/_pytest/mark/structures.py testing/test_mark.py Not-tested: testing/python/metafunc.py because hypothesis is not installed in this environment. Co-authored-by: OpenAI Codex <codex@openai.com>
for more information, see https://pre-commit.ci
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.
This turns a
TypeErrorduring collection into a normalparametrizecollection error when tuple-style argnames receive a scalar parameter set.For example,
@pytest.mark.parametrize("x,", [None])now points at the offending test and reports that the parameter set should be a sequence, instead of showing an internallen(None)crash.I added a regression test for the
Nonecase and a changelog entry.I used AI assistance while preparing this change, reviewed the patch locally, and take responsibility for the contribution.
Checks run locally:
testing/python/metafunc.pywas not run locally becausehypothesisis not installed in this environment.Checklist:
parametrizecauses obfuscated crash #14619.changelog/14619.bugfix.rst.AUTHORS.