@@ -1253,7 +1253,9 @@ def __init__(
1253
1253
def __repr__ (self ) -> str :
1254
1254
return f"<pytest_fixture({ self ._fixture_function } )>"
1255
1255
1256
- def __get__ (self , instance , owner = None ):
1256
+ def __get__ (
1257
+ self , instance : object , owner : type | None = None
1258
+ ) -> FixtureFunctionDefinition :
1257
1259
"""Behave like a method if the function it was applied to was a method."""
1258
1260
return FixtureFunctionDefinition (
1259
1261
function = self ._fixture_function ,
@@ -1747,6 +1749,35 @@ def _register_fixture(
1747
1749
if autouse :
1748
1750
self ._nodeid_autousenames .setdefault (nodeid or "" , []).append (name )
1749
1751
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
+
1750
1781
@overload
1751
1782
def parsefactories (
1752
1783
self ,
@@ -1827,6 +1858,9 @@ def parsefactories(
1827
1858
ids = marker .ids ,
1828
1859
autouse = marker .autouse ,
1829
1860
)
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 )
1830
1864
1831
1865
def getfixturedefs (
1832
1866
self , argname : str , node : nodes .Node
0 commit comments