Skip to content

Commit 8730a7b

Browse files
authored
Merge pull request #7687 from bluetech/idval-notset
python: fix empty parametrize() leading to "NotSetType.token" id
2 parents 00996ad + a267a62 commit 8730a7b

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

changelog/7686.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed `NotSetType.token` being used as the parameter ID when the parametrization list is empty.
2+
Regressed in pytest 6.0.0.

src/_pytest/python.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,9 @@ def _idval(
12931293
return str(val)
12941294
elif isinstance(val, REGEX_TYPE):
12951295
return ascii_escaped(val.pattern)
1296+
elif val is NOTSET:
1297+
# Fallback to default. Note that NOTSET is an enum.Enum.
1298+
pass
12961299
elif isinstance(val, enum.Enum):
12971300
return str(val)
12981301
elif isinstance(getattr(val, "__name__", None), str):

testing/python/metafunc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from _pytest import python
2222
from _pytest.compat import _format_args
2323
from _pytest.compat import getfuncargnames
24+
from _pytest.compat import NOTSET
2425
from _pytest.outcomes import fail
2526
from _pytest.pytester import Testdir
2627
from _pytest.python import _idval
@@ -359,6 +360,14 @@ def test_function():
359360
for val, expected in values:
360361
assert _idval(val, "a", 6, None, nodeid=None, config=None) == expected
361362

363+
def test_notset_idval(self) -> None:
364+
"""Test that a NOTSET value (used by an empty parameterset) generates
365+
a proper ID.
366+
367+
Regression test for #7686.
368+
"""
369+
assert _idval(NOTSET, "a", 0, None, nodeid=None, config=None) == "a0"
370+
362371
def test_idmaker_autoname(self) -> None:
363372
"""#250"""
364373
result = idmaker(

0 commit comments

Comments
 (0)