@@ -1253,7 +1253,9 @@ def __init__(
12531253 def __repr__ (self ) -> str :
12541254 return f"<pytest_fixture({ self ._fixture_function } )>"
12551255
1256- def __get__ (self , instance , owner = None ):
1256+ def __get__ (
1257+ self , instance : object , owner : type | None = None
1258+ ) -> FixtureFunctionDefinition :
12571259 """Behave like a method if the function it was applied to was a method."""
12581260 return FixtureFunctionDefinition (
12591261 function = self ._fixture_function ,
@@ -1747,6 +1749,35 @@ def _register_fixture(
17471749 if autouse :
17481750 self ._nodeid_autousenames .setdefault (nodeid or "" , []).append (name )
17491751
1752+ def _check_for_wrapped_fixture (
1753+ self , holder : object , name : str , obj : object , nodeid : str | None
1754+ ) -> None :
1755+ """Check if an object might be a fixture wrapped in decorators and warn if so."""
1756+ # Only check objects that are not None and not already FixtureFunctionDefinition
1757+ if obj is None :
1758+ return
1759+ try :
1760+ maybe_def = get_real_func (obj )
1761+ except Exception :
1762+ warnings .warn (
1763+ f"could not get real function for fixture { name } on { holder } " ,
1764+ stacklevel = 2 ,
1765+ )
1766+ else :
1767+ if isinstance (maybe_def , FixtureFunctionDefinition ):
1768+ fixture_func = maybe_def ._get_wrapped_function ()
1769+ self ._issue_fixture_wrapped_warning (name , nodeid , fixture_func )
1770+
1771+ def _issue_fixture_wrapped_warning (
1772+ self , fixture_name : str , nodeid : str | None , fixture_func : Any
1773+ ) -> None :
1774+ """Issue a warning about a fixture that cannot be discovered due to decorators."""
1775+ from _pytest .warning_types import PytestWarning
1776+ from _pytest .warning_types import warn_explicit_for
1777+
1778+ msg = f"cannot discover { fixture_name } due to being wrapped in decorators"
1779+ warn_explicit_for (fixture_func , PytestWarning (msg ))
1780+
17501781 @overload
17511782 def parsefactories (
17521783 self ,
@@ -1827,6 +1858,9 @@ def parsefactories(
18271858 ids = marker .ids ,
18281859 autouse = marker .autouse ,
18291860 )
1861+ else :
1862+ # Check if this might be a wrapped fixture that we can't discover
1863+ self ._check_for_wrapped_fixture (holderobj , name , obj_ub , nodeid )
18301864
18311865 def getfixturedefs (
18321866 self , argname : str , node : nodes .Node
0 commit comments