Skip to content

Conversation

@RonnyPfannschmidt
Copy link
Member

Make "arg," behave like ("arg",) by detecting trailing comma and not wrapping tuple values.

Fixes #719

…v#719)

Make "arg," behave like ("arg",) by not wrapping tuple values.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Claude Opus 4 <claude@anthropic.com>
Copilot AI review requested due to automatic review settings January 18, 2026 09:57
@RonnyPfannschmidt RonnyPfannschmidt added type: bug problem that needs to be addressed topic: parametrize related to @pytest.mark.parametrize labels Jan 18, 2026
@psf-chronographer psf-chronographer bot added bot:chronographer:provided (automation) changelog entry is part of PR labels Jan 18, 2026
@RonnyPfannschmidt RonnyPfannschmidt added the backport 9.0.x apply to PRs at any point; backports the changes to the 9.0.x branch label Jan 18, 2026
Copy link

Copilot AI left a 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_args method to detect trailing commas in string argnames and adjust the force_tuple flag 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 9.0.x apply to PRs at any point; backports the changes to the 9.0.x branch bot:chronographer:provided (automation) changelog entry is part of PR topic: parametrize related to @pytest.mark.parametrize type: bug problem that needs to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest.mark.parametrize string-based parameter list doesn't handle single element tuples

1 participant