Skip to content

Commit 0115b71

Browse files
authored
Merge pull request #7688 from nicoddemus/backport-7687
2 parents 79d0d3e + 9a91b67 commit 0115b71

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
@@ -1254,6 +1254,9 @@ def _idval(
12541254
return str(val)
12551255
elif isinstance(val, REGEX_TYPE):
12561256
return ascii_escaped(val.pattern)
1257+
elif val is NOTSET:
1258+
# Fallback to default. Note that NOTSET is an enum.Enum.
1259+
pass
12571260
elif isinstance(val, enum.Enum):
12581261
return str(val)
12591262
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
@@ -19,6 +19,7 @@
1919
import pytest
2020
from _pytest import fixtures
2121
from _pytest import python
22+
from _pytest.compat import NOTSET
2223
from _pytest.outcomes import fail
2324
from _pytest.pytester import Testdir
2425
from _pytest.python import _idval
@@ -363,6 +364,14 @@ def test_function():
363364
for val, expected in values:
364365
assert _idval(val, "a", 6, None, nodeid=None, config=None) == expected
365366

367+
def test_notset_idval(self) -> None:
368+
"""Test that a NOTSET value (used by an empty parameterset) generates
369+
a proper ID.
370+
371+
Regression test for #7686.
372+
"""
373+
assert _idval(NOTSET, "a", 0, None, nodeid=None, config=None) == "a0"
374+
366375
def test_idmaker_autoname(self) -> None:
367376
"""#250"""
368377
result = idmaker(

0 commit comments

Comments
 (0)