Skip to content

Commit 00ba195

Browse files
committed
Fix tests
1 parent 71c9581 commit 00ba195

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/_pytest/compat.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ def getfuncargnames(
117117
118118
The name parameter should be the original name in which the function was collected.
119119
"""
120+
# if name == "session_request":
121+
# import pdb
122+
# breakpoint()
123+
120124
# TODO(RonnyPfannschmidt): This function should be refactored when we
121125
# revisit fixtures. The fixture mechanism should ask the node for
122126
# the fixture names, and not try to obtain directly from the
@@ -234,6 +238,20 @@ def get_real_func(obj):
234238
return obj
235239

236240

241+
def get_real_method(obj, holder):
242+
"""Attempt to obtain the real function object that might be wrapping
243+
``obj``, while at the same time returning a bound method to ``holder`` if
244+
the original object was a bound method."""
245+
try:
246+
is_method = hasattr(obj, "__func__")
247+
obj = get_real_func(obj)
248+
except Exception: # pragma: no cover
249+
return obj
250+
if is_method and hasattr(obj, "__get__") and callable(obj.__get__):
251+
obj = obj.__get__(holder)
252+
return obj
253+
254+
237255
def getimfunc(func):
238256
try:
239257
return func.__func__

src/_pytest/fixtures.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from _pytest._io import TerminalWriter
4545
from _pytest.compat import assert_never
4646
from _pytest.compat import get_real_func
47+
from _pytest.compat import get_real_method
4748
from _pytest.compat import getfuncargnames
4849
from _pytest.compat import getimfunc
4950
from _pytest.compat import getlocation
@@ -1743,12 +1744,15 @@ def parsefactories(
17431744
# access below can raise. safe_getattr() ignores such exceptions.
17441745
obj_ub = safe_getattr(holderobj_tp, name, None)
17451746
if isinstance(obj_ub, FixtureFunctionDefinition):
1746-
marker = getfixturemarker(obj_ub)
1747-
if marker is None:
1748-
raise Exception("marker was none")
1747+
marker = obj_ub._fixture_function_marker
17491748
if marker.name:
17501749
name = marker.name
1751-
func = get_real_func(obj_ub)
1750+
1751+
# OK we know it is a fixture -- now safe to look up on the _instance_.
1752+
obj = getattr(holderobj_tp, name)
1753+
1754+
func = get_real_method(obj, holderobj)
1755+
17521756
self._register_fixture(
17531757
name=name,
17541758
nodeid=nodeid,

0 commit comments

Comments
 (0)