Skip to content

Improve parametrize error for scalar parameter sets#14621

Open
mike-lmctl wants to merge 2 commits into
pytest-dev:mainfrom
mike-lmctl:fix-parametrize-scalar-values-error
Open

Improve parametrize error for scalar parameter sets#14621
mike-lmctl wants to merge 2 commits into
pytest-dev:mainfrom
mike-lmctl:fix-parametrize-scalar-values-error

Conversation

@mike-lmctl

Copy link
Copy Markdown

Closes #14619.

This turns a TypeError during collection into a normal parametrize collection 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 internal len(None) crash.

I added a regression test for the None case 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:

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
PYTHONPATH=src python3 -m pytest testing/test_mark.py -q
git diff --check -- src/_pytest/mark/structures.py testing/test_mark.py changelog/14619.bugfix.rst AUTHORS
python3 -m py_compile src/_pytest/mark/structures.py testing/test_mark.py

testing/python/metafunc.py was not run locally because hypothesis is not installed in this environment.

Checklist:

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>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jun 17, 2026
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