Skip to content

fix(parametrize): handle trailing comma in string argnames#14125

Merged
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:fix-719-parametrize-trailing-comma
Jan 29, 2026
Merged

fix(parametrize): handle trailing comma in string argnames#14125
RonnyPfannschmidt merged 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:fix-719-parametrize-trailing-comma

Conversation

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

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

Fixes #719

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

Copilot AI left a comment

Copy link
Copy Markdown

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.

@RonnyPfannschmidt RonnyPfannschmidt force-pushed the fix-719-parametrize-trailing-comma branch from 8e09ae7 to c5aefb5 Compare January 29, 2026 16:08
@RonnyPfannschmidt RonnyPfannschmidt force-pushed the fix-719-parametrize-trailing-comma branch from c5aefb5 to 5e7ea97 Compare January 29, 2026 16:08
…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 <ai@cursor.sh>
Co-authored-by: Anthropic Claude Opus 4.5 <claude@anthropic.com>
@RonnyPfannschmidt RonnyPfannschmidt force-pushed the fix-719-parametrize-trailing-comma branch from 5e7ea97 to 3fc824a Compare January 29, 2026 17:20
@RonnyPfannschmidt RonnyPfannschmidt merged commit 5f59a74 into pytest-dev:main Jan 29, 2026
33 checks passed
@patchback

patchback Bot commented Jan 29, 2026

Copy link
Copy Markdown

Backport to 9.0.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/9.0.x/5f59a745ed777ca1943f6c2de137c3de912ba58a/pr-14125

Backported as #14149

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback Bot pushed a commit that referenced this pull request Jan 29, 2026
…trailing-comma

fix(parametrize): handle trailing comma in string argnames

(cherry picked from commit 5f59a74)
himani2411 pushed a commit to himani2411/aws-parallelcluster that referenced this pull request Jun 15, 2026
pytest 9.1.0 (released 2026-06-13) shipped pytest-dev/pytest#14125, which
fixes pytest-dev/pytest#719: a trailing comma in a string argnames value
(e.g. "args, " or "config_file_name,") now behaves like the tuple form
("arg",) and unpacks each value as a tuple. Before 9.1.0 the trailing comma
was discarded and the value was passed as-is for the single argname, so these
tests passed by accident.

After the change pytest unpacks each value, and our non-tuple values no longer
match the single argname, failing collection:
  - "args, " + value {}            -> names (1) != values (0)
  - "config_file_name," + "config.yaml" -> names (1) != values (11)
    (the string is unpacked into its 11 characters)

These tests date back to 2021 and were unchanged; tox does not pin pytest, so
CI picked up 9.1.0 two days after its release and exposed the latent issue.

Fix: drop the trailing comma so each value is treated as a single argument on
every pytest version.

Refs:
  pytest-dev/pytest#14125
  pytest-dev/pytest#719
  pytest 9.1.0 changelog: https://docs.pytest.org/en/stable/changelog.html
himani2411 pushed a commit to aws/aws-parallelcluster that referenced this pull request Jun 16, 2026
pytest 9.1.0 (released 2026-06-13) shipped pytest-dev/pytest#14125, which
fixes pytest-dev/pytest#719: a trailing comma in a string argnames value
(e.g. "args, " or "config_file_name,") now behaves like the tuple form
("arg",) and unpacks each value as a tuple. Before 9.1.0 the trailing comma
was discarded and the value was passed as-is for the single argname, so these
tests passed by accident.

After the change pytest unpacks each value, and our non-tuple values no longer
match the single argname, failing collection:
  - "args, " + value {}            -> names (1) != values (0)
  - "config_file_name," + "config.yaml" -> names (1) != values (11)
    (the string is unpacked into its 11 characters)

These tests date back to 2021 and were unchanged; tox does not pin pytest, so
CI picked up 9.1.0 two days after its release and exposed the latent issue.

Fix: drop the trailing comma so each value is treated as a single argument on
every pytest version.

Refs:
  pytest-dev/pytest#14125
  pytest-dev/pytest#719
  pytest 9.1.0 changelog: https://docs.pytest.org/en/stable/changelog.html
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 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

3 participants