56
56
_ScopeName = Literal ["session" , "package" , "module" , "class" , "function" ]
57
57
_T = TypeVar ("_T" )
58
58
59
- SimpleFixtureFunction = TypeVar (
60
- "SimpleFixtureFunction" , bound = Callable [..., Awaitable [object ]]
59
+ FixtureFunctionT = TypeVar (
60
+ "FixtureFunctionT" ,
61
+ bound = Union [Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]],
61
62
)
62
- FactoryFixtureFunction = TypeVar (
63
- "FactoryFixtureFunction" , bound = Callable [..., AsyncIterator [object ]]
63
+ FixtureFunctionU = TypeVar (
64
+ "FixtureFunctionU" ,
65
+ bound = Union [Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]],
64
66
)
65
- FixtureFunction = Union [SimpleFixtureFunction , FactoryFixtureFunction ]
66
- FixtureFunctionMarker = Callable [[FixtureFunction ], FixtureFunction ]
67
+ FixtureFunctionType = Union [
68
+ Callable [..., Awaitable [Any ]], Callable [..., AsyncIterator [Any ]]
69
+ ]
70
+ FixtureFunctionMarker = Callable [[FixtureFunctionT ], FixtureFunctionT ]
67
71
68
72
69
73
class PytestAsyncioError (Exception ):
@@ -117,7 +121,7 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None
117
121
118
122
@overload
119
123
def fixture (
120
- fixture_function : FixtureFunction ,
124
+ fixture_function : FixtureFunctionT ,
121
125
* ,
122
126
scope : _ScopeName | Callable [[str , Config ], _ScopeName ] = ...,
123
127
loop_scope : _ScopeName | None = ...,
@@ -129,7 +133,7 @@ def fixture(
129
133
| None
130
134
) = ...,
131
135
name : str | None = ...,
132
- ) -> FixtureFunction : ...
136
+ ) -> FixtureFunctionT : ...
133
137
134
138
135
139
@overload
@@ -146,22 +150,22 @@ def fixture(
146
150
| None
147
151
) = ...,
148
152
name : str | None = None ,
149
- ) -> FixtureFunctionMarker : ...
153
+ ) -> FixtureFunctionMarker [ FixtureFunctionU ] : ...
150
154
151
155
152
156
def fixture (
153
- fixture_function : FixtureFunction | None = None ,
157
+ fixture_function : FixtureFunctionT | None = None ,
154
158
loop_scope : _ScopeName | None = None ,
155
159
** kwargs : Any ,
156
- ) -> FixtureFunction | FixtureFunctionMarker :
160
+ ) -> FixtureFunctionT | FixtureFunctionMarker [ FixtureFunctionU ] :
157
161
if fixture_function is not None :
158
162
_make_asyncio_fixture_function (fixture_function , loop_scope )
159
163
return pytest .fixture (fixture_function , ** kwargs )
160
164
161
165
else :
162
166
163
167
@functools .wraps (fixture )
164
- def inner (fixture_function : FixtureFunction ) -> FixtureFunction :
168
+ def inner (fixture_function : FixtureFunctionU ) -> FixtureFunctionU :
165
169
return fixture (fixture_function , loop_scope = loop_scope , ** kwargs )
166
170
167
171
return inner
@@ -679,7 +683,9 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
679
683
680
684
# A stack used to push package-scoped loops during collection of a package
681
685
# and pop those loops during collection of a Module
682
- __package_loop_stack : list [FixtureFunctionMarker | FixtureFunction ] = []
686
+ __package_loop_stack : list [
687
+ FixtureFunctionMarker [FixtureFunctionType ] | FixtureFunctionType
688
+ ] = []
683
689
684
690
685
691
@pytest .hookimpl
0 commit comments