File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -462,7 +462,7 @@ def _format_assertmsg(obj: object) -> str:
462462
463463def _should_repr_global_name (obj : object ) -> bool :
464464 if callable (obj ):
465- return hasattr (obj , "__pytest_wrapped__ " )
465+ return hasattr (obj , "_pytestfixturefunction " )
466466
467467 try :
468468 return not hasattr (obj , "__name__" )
Original file line number Diff line number Diff line change @@ -1200,6 +1200,9 @@ def __init__(
12001200 ):
12011201 self .name = fixture_function_marker .name or function .__name__
12021202 self .__name__ = self .name
1203+ # This attribute is only used to check if an arbitrary python object is a fixture.
1204+ # Using isinstance on every object in code might execute code that is not intended to be executed.
1205+ # Like lazy loaded classes.
12031206 self ._pytestfixturefunction = fixture_function_marker
12041207 self .__pytest_wrapped__ = _PytestWrapper (function )
12051208 self .fixture_function_marker = fixture_function_marker
Original file line number Diff line number Diff line change @@ -744,6 +744,23 @@ def __repr__(self):
744744 assert "UnicodeDecodeError" not in msg
745745 assert "UnicodeEncodeError" not in msg
746746
747+ def test_assert_fixture (self , pytester : Pytester ) -> None :
748+ pytester .makepyfile (
749+ """\
750+ import pytest
751+ @pytest.fixture
752+ def fixt():
753+ return 42
754+
755+ def test_something(): # missing "fixt" argument
756+ assert fixt == 42
757+ """
758+ )
759+ result = pytester .runpytest ()
760+ result .stdout .fnmatch_lines (
761+ ["*assert pytest_fixture(<function fixt at *>) == 42*" ]
762+ )
763+
747764
748765class TestRewriteOnImport :
749766 def test_pycache_is_a_file (self , pytester : Pytester ) -> None :
You can’t perform that action at this time.
0 commit comments