Skip to content

Commit 7a84381

Browse files
committed
Handle scenarios where fixture is renamed in decorator
1 parent 00ba195 commit 7a84381

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/_pytest/fixtures.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,13 +1743,17 @@ def parsefactories(
17431743
# The attribute can be an arbitrary descriptor, so the attribute
17441744
# access below can raise. safe_getattr() ignores such exceptions.
17451745
obj_ub = safe_getattr(holderobj_tp, name, None)
1746-
if isinstance(obj_ub, FixtureFunctionDefinition):
1746+
if type(obj_ub) is FixtureFunctionDefinition:
17471747
marker = obj_ub._fixture_function_marker
17481748
if marker.name:
17491749
name = marker.name
17501750

17511751
# OK we know it is a fixture -- now safe to look up on the _instance_.
1752-
obj = getattr(holderobj_tp, name)
1752+
try:
1753+
obj = getattr(holderobj, name)
1754+
# if the fixture is named in the decorator we cannot find it in the module
1755+
except AttributeError:
1756+
obj = obj_ub
17531757

17541758
func = get_real_method(obj, holderobj)
17551759

0 commit comments

Comments
 (0)