Skip to content

Commit

Permalink
Refactor change in PR#7687
Browse files Browse the repository at this point in the history
In pytest-dev#7687 a bugfix was added
after NOTSET was changed to a singleton enum, which ended up breaking
ID generation when it checked for isinstance(Enum).

That change, however, did not update the code path in the same ID
generation when used as an idfn function.

This adjusts the logic to handle both cases.
  • Loading branch information
alexharv074 committed Sep 19, 2021
1 parent 60e995d commit 12a5571
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@ def _idval(
nodeid: Optional[str],
config: Optional[Config],
) -> str:
if val is NOTSET:
# Fallback to default. Note that NOTSET is an enum.Enum.
return str(argname) + str(idx)

if idfn:
try:
generated_id = idfn(val)
Expand All @@ -1334,15 +1338,13 @@ 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):
# Name of a class, function, module, etc.
name: str = getattr(val, "__name__")
return name

return str(argname) + str(idx)


Expand Down

0 comments on commit 12a5571

Please sign in to comment.