Skip to content

Duplicated parameters in parametrize marker#11489

Merged
Zac-HD merged 16 commits intopytest-dev:mainfrom
TanyaAgarwal28:duplicated_parameters_in_parametrize_marker
Oct 8, 2023
Merged

Duplicated parameters in parametrize marker#11489
Zac-HD merged 16 commits intopytest-dev:mainfrom
TanyaAgarwal28:duplicated_parameters_in_parametrize_marker

Conversation

@TanyaAgarwal28
Copy link
Copy Markdown
Contributor

@TanyaAgarwal28 TanyaAgarwal28 commented Oct 8, 2023

Problem Statement

What's the problem this feature will solve?
The current behavior of pytest in handling duplicated values in parametrize can lead to confusion regarding the actual parameter values used in tests. This PR aims to address this issue by providing clear and unambiguous parameter identifiers.

[maintainer edit to link the issue: fixes #11456]

Solution Description

The proposed solution involves modifying the make_unique_parameterset_ids method in the Python.py class. This change will ensure that unique identifiers are generated for ParameterSets, eliminating any confusion caused by duplicated values.

  • When a parameter identifier ends in a digit, a new identifier will be generated in the format "{id}_{suffix}", where suffix is a numeric counter.
  • If the new identifier is already present in the set of resolved identifiers, the counter will be incremented until a unique identifier is obtained.
  • This approach guarantees the uniqueness of identifiers, even when the original identifiers have digit endings.

Copy link
Copy Markdown
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you PR Tanya!

Comment thread changelog/11456.bugfix.rst Outdated
Comment thread src/_pytest/python.py
@Zac-HD Zac-HD enabled auto-merge (squash) October 8, 2023 17:11
@Zac-HD Zac-HD merged commit af9b1dc into pytest-dev:main Oct 8, 2023
@nicoddemus nicoddemus mentioned this pull request Oct 10, 2023
4 tasks
@pllim
Copy link
Copy Markdown
Contributor

pllim commented Oct 27, 2023

Hello! I think this PR might have broken something that used to work. We have a test downstream that parametrize values that include empty strings. The id[-1] access broken that use case. See astropy/astropy#15548

@Zac-HD
Copy link
Copy Markdown
Member

Zac-HD commented Oct 27, 2023

Yep, that's a regression which we should fix! Would you mind opening a new issue for it?

@pllim
Copy link
Copy Markdown
Contributor

pllim commented Oct 27, 2023

Thanks for the quick reply! I opened #11563 🙏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated parameters in @pytest.mark.parametrize

3 participants