Repository navigation
Improve parametrize error for scalar parameter sets - #14621
mike-lmctl wants to merge 2 commits into
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>
bc13fe9 to
76907f3
Compare
DTiming24
left a comment
There was a problem hiding this comment.
Good improvement turning len(None) into a collection error. Since the repro in the body uses @pytest.mark.parametrize("x,", [None]), I think the error message should probably mention the single-value tuple syntax explicitly (('value',)), because that's the quickest fix users can make.
This comment was marked as low quality.
This comment was marked as low quality.
The collection error now points users at the immediate fix for tuple-style single-argument parametrization: wrapping the value as a one-element tuple. 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: git diff --check -- src/_pytest/mark/structures.py testing/test_mark.py Tested: python3 -m py_compile src/_pytest/mark/structures.py testing/test_mark.py
|
This was closed today without a merge. Is #14619 available for someone else to take over, or do you plan to continue it? I would like to improve the parameter-value diagnostics while preserving the existing tuple-style behaviour. |
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
Actually please reopen
This slipped out of my review window
It's Actually good to go
|
The source fork is currently unavailable: @RonnyPfannschmidt, if the author cannot restore the source and reopen this PR, would you prefer the approved patch carried into a fresh PR with Mike Ma’s authorship and credit preserved? I will hold off on a replacement pending agreement. |
|
I just had Claude do a preservation Ill wait a bit to see if comments from @mike-lmctl come in and merge mid week unless a complaint comes up |
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.