Skip to content

Commit 888f707

Browse files
committed
refactor: remove _pytestfixturefunction attribute
1 parent 3752f6e commit 888f707

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def _format_assertmsg(obj: object) -> str:
462462

463463
def _should_repr_global_name(obj: object) -> bool:
464464
if callable(obj):
465-
return hasattr(obj, "_pytestfixturefunction")
465+
return hasattr(obj, "_fixture_function_marker")
466466

467467
try:
468468
return not hasattr(obj, "__name__")

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def get_real_func(obj):
217217
start_obj = obj
218218
for _ in range(100):
219219
if isinstance(obj, FixtureFunctionDefinition):
220-
obj = obj.get_real_func()
220+
obj = obj._get_wrapped_function()
221221
break
222222
new_obj = getattr(obj, "__wrapped__", None)
223223
if new_obj is None:

src/_pytest/fixtures.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def getfixturemarker(obj: object) -> Optional["FixtureFunctionMarker"]:
155155
exceptions."""
156156
return cast(
157157
Optional[FixtureFunctionMarker],
158-
safe_getattr(obj, "_pytestfixturefunction", None),
158+
safe_getattr(obj, "_fixture_function_marker", None),
159159
)
160160

161161

@@ -1193,7 +1193,7 @@ class FixtureFunctionDefinition:
11931193

11941194
def __init__(
11951195
self,
1196-
function: Callable[..., object],
1196+
function: Callable[..., Any],
11971197
fixture_function_marker: FixtureFunctionMarker,
11981198
instance: Optional[type] = None,
11991199
):
@@ -1202,17 +1202,16 @@ def __init__(
12021202
# This attribute is only used to check if an arbitrary python object is a fixture.
12031203
# Using isinstance on every object in code might execute code that is not intended to be executed.
12041204
# Like lazy loaded classes.
1205-
self._pytestfixturefunction = fixture_function_marker
1206-
self.fixture_function_marker = fixture_function_marker
1207-
self.fixture_function = function
1208-
self.instance = instance
1205+
self._fixture_function_marker = fixture_function_marker
1206+
self._fixture_function = function
1207+
self._instance = instance
12091208

12101209
def __repr__(self) -> str:
1211-
return f"pytest_fixture({self.fixture_function})"
1210+
return f"pytest_fixture({self._fixture_function})"
12121211

12131212
def __get__(self, instance, owner=None):
12141213
return FixtureFunctionDefinition(
1215-
self.fixture_function, self.fixture_function_marker, instance
1214+
self._fixture_function, self._fixture_function_marker, instance
12161215
)
12171216

12181217
def __call__(self, *args: Any, **kwds: Any) -> Any:
@@ -1224,10 +1223,10 @@ def __call__(self, *args: Any, **kwds: Any) -> Any:
12241223
)
12251224
fail(message, pytrace=False)
12261225

1227-
def get_real_func(self):
1228-
if self.instance is not None:
1229-
return self.fixture_function.__get__(self.instance)
1230-
return self.fixture_function
1226+
def _get_wrapped_function(self):
1227+
if self._instance is not None:
1228+
return self._fixture_function.__get__(self._instance)
1229+
return self._fixture_function
12311230

12321231

12331232
@overload
@@ -1769,7 +1768,7 @@ def parsefactories(
17691768
if isinstance(obj, FixtureFunctionDefinition):
17701769
if marker.name:
17711770
name = marker.name
1772-
func = obj.get_real_func()
1771+
func = obj._get_wrapped_function()
17731772
self._register_fixture(
17741773
name=name,
17751774
nodeid=nodeid,

testing/code/test_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def deco_fixture():
481481
# Since deco_fixture is now an instance of FixtureFunctionDef the getsource function will not work on it.
482482
with pytest.raises(Exception):
483483
inspect.getsource(deco_fixture)
484-
src = inspect.getsource(deco_fixture.get_real_func())
484+
src = inspect.getsource(deco_fixture._get_wrapped_function())
485485
assert src == " @pytest.fixture\n def deco_fixture():\n assert False\n"
486486
# Make sure the decorator is not a wrapped function
487487
assert not str(Source(deco_fixture)).startswith("@functools.wraps(function)")

testing/test_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def wrapped_func3():
8383
pass
8484

8585
wrapped_func4 = decorator(wrapped_func3)
86-
assert get_real_func(wrapped_func4) is wrapped_func3.get_real_func()
86+
assert get_real_func(wrapped_func4) is wrapped_func3._get_wrapped_function()
8787

8888

8989
def test_get_real_func_partial() -> None:

0 commit comments

Comments
 (0)