-
-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(parametrize): handle trailing comma in string argnames #14125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(parametrize): handle trailing comma in string argnames #14125
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in pytest.mark.parametrize where string argnames with trailing commas (e.g., "arg,") were not behaving like their tuple equivalents (e.g., ("arg",)). The fix ensures that when a single-argument string has a trailing comma, argvalues are treated as tuples to unpack rather than values to wrap.
Changes:
- Modified the
_parse_parametrize_argsmethod to detect trailing commas in string argnames and adjust theforce_tupleflag accordingly - Added comprehensive unit and functional tests to verify the behavior
- Added a changelog entry documenting the fix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/_pytest/mark/structures.py | Added trailing comma detection logic to make "arg," behave like ("arg",) by adjusting the force_tuple flag |
| testing/python/metafunc.py | Added unit test verifying that tuple form, string with trailing comma, and string without comma all behave correctly; added functional test verifying the behavior in actual test execution |
| changelog/719.bugfix.rst | Added changelog entry documenting the bugfix for issue #719 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e09ae7 to
c5aefb5
Compare
c5aefb5 to
5e7ea97
Compare
…v#719) Make `"arg,"` behave like `("arg",)` by detecting trailing comma and not wrapping tuple values. This allows users to use trailing comma syntax in string argnames for single-parameter parametrize. Fixes pytest-dev#719 Co-authored-by: Cursor AI <[email protected]> Co-authored-by: Anthropic Claude Opus 4.5 <[email protected]>
5e7ea97 to
3fc824a
Compare
Backport to 9.0.x: 💚 backport PR created✅ Backport PR branch: Backported as #14149 🤖 @patchback |
…trailing-comma fix(parametrize): handle trailing comma in string argnames (cherry picked from commit 5f59a74)
Make
"arg,"behave like("arg",)by detecting trailing comma and not wrapping tuple values.Fixes #719