77"""
88from contextlib import _GeneratorContextManager
99from functools import cached_property , wraps
10+ from inspect import isgeneratorfunction , Signature
1011from os .path import dirname
1112from unittest import mock
1213
@@ -38,7 +39,7 @@ def fixture(func=None, /, scope="function", autouse=False):
3839 a lower scope to retrieve the value of the fixture.
3940 """
4041 def fixture (func ):
41- if not _api . is_generator (func ):
42+ if not isgeneratorfunction (func ):
4243 return UnmagicFixture .create (func , scope , autouse )
4344 return UnmagicFixture (func , scope , autouse )
4445 return fixture if func is None else fixture (func )
@@ -78,7 +79,7 @@ def setup_fixtures():
7879 )
7980 func , scope = func .func , func .scope
8081
81- if _api . is_generator (func ):
82+ if isgeneratorfunction (func ):
8283 @wraps (func )
8384 def run_with_fixtures (* args , ** kw ):
8485 setup_fixtures ()
@@ -141,11 +142,10 @@ def create(cls, fixture, scope="function", autouse=False):
141142 def func ():
142143 with fixture as value :
143144 yield value
144- func .__pytest_wrapped__ = _api .Wrapper (wrapped )
145145 func .__unmagic_wrapped__ = outer
146- # delete __wrapped__ to prevent pytest from
147- # introspecting arguments from wrapped function
148- del func .__wrapped__
146+ func . __wrapped__ = wrapped
147+ # prevent pytest from introspecting arguments from wrapped function
148+ func .__signature__ = Signature ()
149149 return cls (func , scope , autouse )
150150
151151 def __init__ (self , func , scope , autouse ):
@@ -163,11 +163,6 @@ def _id(self):
163163 def unmagic_fixtures (self ):
164164 return self .func .unmagic_fixtures
165165
166- @property
167- def __pytest_wrapped__ (self ):
168- wrapped = getattr (self .func , "__pytest_wrapped__" , None )
169- return _api .Wrapper (self .func ) if wrapped is None else wrapped
170-
171166 @property
172167 def __name__ (self ):
173168 return self .func .__name__
@@ -202,7 +197,7 @@ def _register(self, node):
202197 scope_node_id = ""
203198 else :
204199 scope_node_id = _SCOPE_NODE_ID [self .scope ](node .nodeid )
205- assert _api . is_generator (self .func ), repr (self )
200+ assert isgeneratorfunction (self .func ), repr (self )
206201 _api .register_fixture (
207202 node .session ,
208203 name = self ._id ,
0 commit comments