Skip to content
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 crash using empty string for parametrized value more than once #11564

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/11563.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed crash when using an empty string for the same parametrized value more than once.
2 changes: 1 addition & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def make_unique_parameterset_ids(self) -> List[str]:
for index, id in enumerate(resolved_ids):
if id_counts[id] > 1:
suffix = ""
if id[-1].isdigit():
if id and id[-1].isdigit():
suffix = "_"
new_id = f"{id}{suffix}{id_suffixes[id]}"
while new_id in set(resolved_ids):
Expand Down
7 changes: 7 additions & 0 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,13 @@ def getini(self, name):
).make_unique_parameterset_ids()
assert result == [expected]

def test_idmaker_duplicated_empty_str(self) -> None:
"""Regression test for empty strings parametrized more than once (#11563)."""
result = IdMaker(
("a",), [pytest.param(""), pytest.param("")], None, None, None, None, None
).make_unique_parameterset_ids()
assert result == ["0", "1"]

def test_parametrize_ids_exception(self, pytester: Pytester) -> None:
"""
:param pytester: the instance of Pytester class, a temporary
Expand Down
Loading