Skip to content

Commit 7156a97

Browse files
committed
Fix crash using empty string for parametrized value more than once
Fixes #11563.
1 parent ed8701a commit 7156a97

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

changelog/11563.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed crash when using an empty string for the same parametrized value more than once.

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def make_unique_parameterset_ids(self) -> List[str]:
10031003
for index, id in enumerate(resolved_ids):
10041004
if id_counts[id] > 1:
10051005
suffix = ""
1006-
if id[-1].isdigit():
1006+
if id and id[-1].isdigit():
10071007
suffix = "_"
10081008
new_id = f"{id}{suffix}{id_suffixes[id]}"
10091009
while new_id in set(resolved_ids):

testing/python/metafunc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,13 @@ def getini(self, name):
626626
).make_unique_parameterset_ids()
627627
assert result == [expected]
628628

629+
def test_idmaker_duplicated_empty_str(self) -> None:
630+
"""Regression test for empty strings parametrized more than once (#11563)."""
631+
result = IdMaker(
632+
("a",), [pytest.param(""), pytest.param("")], None, None, None, None, None
633+
).make_unique_parameterset_ids()
634+
assert result == ["0", "1"]
635+
629636
def test_parametrize_ids_exception(self, pytester: Pytester) -> None:
630637
"""
631638
:param pytester: the instance of Pytester class, a temporary

0 commit comments

Comments
 (0)