Skip to content

Commit 595d62b

Browse files
authored
Merge pull request #6607 from asottile/empty_string_parametrize_nodeid
Fix node ids which contain a parametrized empty-string variable
2 parents 06a7fef + abd5fc8 commit 595d62b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

changelog/6597.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix node ids which contain a parametrized empty-string variable.

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ def getparam(self, name):
873873

874874
@property
875875
def id(self):
876-
return "-".join(map(str, filter(None, self._idlist)))
876+
return "-".join(map(str, self._idlist))
877877

878878
def setmulti2(self, valtypes, argnames, valset, id, marks, scopenum, param_index):
879879
for arg, val in zip(argnames, valset):

testing/python/collect.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ def test_function(arg):
492492
)
493493
assert "foo" in keywords[1] and "bar" in keywords[1] and "baz" in keywords[1]
494494

495+
def test_parametrize_with_empty_string_arguments(self, testdir):
496+
items = testdir.getitems(
497+
"""\
498+
import pytest
499+
500+
@pytest.mark.parametrize('v', ('', ' '))
501+
@pytest.mark.parametrize('w', ('', ' '))
502+
def test(v, w): ...
503+
"""
504+
)
505+
names = {item.name for item in items}
506+
assert names == {"test[-]", "test[ -]", "test[- ]", "test[ - ]"}
507+
495508
def test_function_equality_with_callspec(self, testdir):
496509
items = testdir.getitems(
497510
"""

0 commit comments

Comments
 (0)