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

Merge pull request #7687 from bluetech/idval-notset #7688

Merged
merged 1 commit into from Aug 26, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/7686.bugfix.rst
@@ -0,0 +1,2 @@
Fixed `NotSetType.token` being used as the parameter ID when the parametrization list is empty.
Regressed in pytest 6.0.0.
3 changes: 3 additions & 0 deletions src/_pytest/python.py
Expand Up @@ -1254,6 +1254,9 @@ def _idval(
return str(val)
elif isinstance(val, REGEX_TYPE):
return ascii_escaped(val.pattern)
elif val is NOTSET:
# Fallback to default. Note that NOTSET is an enum.Enum.
pass
elif isinstance(val, enum.Enum):
return str(val)
elif isinstance(getattr(val, "__name__", None), str):
Expand Down
9 changes: 9 additions & 0 deletions testing/python/metafunc.py
Expand Up @@ -19,6 +19,7 @@
import pytest
from _pytest import fixtures
from _pytest import python
from _pytest.compat import NOTSET
from _pytest.outcomes import fail
from _pytest.pytester import Testdir
from _pytest.python import _idval
Expand Down Expand Up @@ -363,6 +364,14 @@ def test_function():
for val, expected in values:
assert _idval(val, "a", 6, None, nodeid=None, config=None) == expected

def test_notset_idval(self) -> None:
"""Test that a NOTSET value (used by an empty parameterset) generates
a proper ID.

Regression test for #7686.
"""
assert _idval(NOTSET, "a", 0, None, nodeid=None, config=None) == "a0"

def test_idmaker_autoname(self) -> None:
"""#250"""
result = idmaker(
Expand Down