diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 818933b6d..a15be6837 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -35,6 +35,7 @@ from _pytest._io.saferepr import saferepr from _pytest._version import version from _pytest.assertion import util from _pytest.config import Config +from _pytest.fixtures import getfixturemarker from _pytest.main import Session from _pytest.pathlib import absolutepath from _pytest.pathlib import fnmatch_ex @@ -462,7 +463,7 @@ def _format_assertmsg(obj: object) -> str: def _should_repr_global_name(obj: object) -> bool: if callable(obj): - return hasattr(obj, "_fixture_function_marker") + return getfixturemarker(obj) is not None try: return not hasattr(obj, "__name__") diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index ea64a17de..449232c80 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -1192,9 +1192,6 @@ class FixtureFunctionDefinition: ): self.name = fixture_function_marker.name or function.__name__ self.__name__ = self.name - # This attribute is used to check if an arbitrary python object is a fixture. - # Using isinstance on every object in code might execute code that is not intended to be executed. - # Like lazy loaded classes. self._fixture_function_marker = fixture_function_marker self._fixture_function = function self._instance = instance