Skip to content

Commit 71b3fe5

Browse files
committed
Remove get_real_func loop
1 parent 3d7416c commit 71b3fe5

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/_pytest/compat.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,11 @@ def get_real_func(obj):
214214
:func:`functools.wraps`, or :func:`functools.partial`, or :func:`pytest.fixture`."""
215215
from _pytest.fixtures import FixtureFunctionDefinition
216216

217-
start_obj = obj
218-
for _ in range(100):
219-
if isinstance(obj, FixtureFunctionDefinition):
220-
obj = obj._get_wrapped_function()
221-
break
222-
new_obj = getattr(obj, "__wrapped__", None)
223-
if new_obj is None:
224-
break
225-
obj = new_obj
226-
else:
227-
from _pytest._io.saferepr import saferepr
217+
obj = inspect.unwrap(obj, stop=lambda x: type(x) is FixtureFunctionDefinition)
218+
219+
if type(obj) == FixtureFunctionDefinition:
220+
obj = obj._get_wrapped_function()
228221

229-
raise ValueError(
230-
f"could not find real function of {saferepr(start_obj)}\nstopped at {saferepr(obj)}"
231-
)
232222
if isinstance(obj, functools.partial):
233223
obj = obj.func
234224
return obj

testing/test_compat.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ def __getattr__(self, attr):
5151

5252
with pytest.raises(
5353
ValueError,
54-
match=(
55-
"could not find real function of <Evil left=900>\n"
56-
"stopped at <Evil left=900>"
57-
),
54+
match=("wrapper loop when unwrapping <Evil left=998>"),
5855
):
5956
get_real_func(evil)
6057

0 commit comments

Comments
 (0)