@@ -1271,7 +1271,9 @@ def __init__(
12711271 def __repr__ (self ) -> str :
12721272 return f"<pytest_fixture({ self ._fixture_function } )>"
12731273
1274- def __get__ (self , instance , owner = None ):
1274+ def __get__ (
1275+ self , instance : object , owner : type | None = None
1276+ ) -> FixtureFunctionDefinition :
12751277 """Behave like a method if the function it was applied to was a method."""
12761278 return FixtureFunctionDefinition (
12771279 function = self ._fixture_function ,
@@ -1765,6 +1767,35 @@ def _register_fixture(
17651767 if autouse :
17661768 self ._nodeid_autousenames .setdefault (nodeid or "" , []).append (name )
17671769
1770+ def _check_for_wrapped_fixture (
1771+ self , holder : object , name : str , obj : object , nodeid : str | None
1772+ ) -> None :
1773+ """Check if an object might be a fixture wrapped in decorators and warn if so."""
1774+ # Only check objects that are not None and not already FixtureFunctionDefinition
1775+ if obj is None :
1776+ return
1777+ try :
1778+ maybe_def = get_real_func (obj )
1779+ except Exception :
1780+ warnings .warn (
1781+ f"could not get real function for fixture { name } on { holder } " ,
1782+ stacklevel = 2 ,
1783+ )
1784+ else :
1785+ if isinstance (maybe_def , FixtureFunctionDefinition ):
1786+ fixture_func = maybe_def ._get_wrapped_function ()
1787+ self ._issue_fixture_wrapped_warning (name , nodeid , fixture_func )
1788+
1789+ def _issue_fixture_wrapped_warning (
1790+ self , fixture_name : str , nodeid : str | None , fixture_func : Any
1791+ ) -> None :
1792+ """Issue a warning about a fixture that cannot be discovered due to decorators."""
1793+ from _pytest .warning_types import PytestWarning
1794+ from _pytest .warning_types import warn_explicit_for
1795+
1796+ msg = f"cannot discover { fixture_name } due to being wrapped in decorators"
1797+ warn_explicit_for (fixture_func , PytestWarning (msg ))
1798+
17681799 @overload
17691800 def parsefactories (
17701801 self ,
@@ -1845,6 +1876,9 @@ def parsefactories(
18451876 ids = marker .ids ,
18461877 autouse = marker .autouse ,
18471878 )
1879+ else :
1880+ # Check if this might be a wrapped fixture that we can't discover
1881+ self ._check_for_wrapped_fixture (holderobj , name , obj_ub , nodeid )
18481882
18491883 def getfixturedefs (
18501884 self , argname : str , node : nodes .Node
0 commit comments