10
10
Iterator ,
11
11
Optional ,
12
12
Protocol ,
13
- Type ,
14
13
Union ,
15
14
overload ,
16
15
)
@@ -208,9 +207,13 @@ def pytest_pyfunc_call(pyfuncitem): # type: ignore[no-untyped-def]
208
207
"""Run coroutines in an event loop instead of a normal function call."""
209
208
fast = pyfuncitem .config .getoption ("--aiohttp-fast" )
210
209
if inspect .iscoroutinefunction (pyfuncitem .function ):
211
- existing_loop = pyfuncitem .funcargs .get (
212
- "proactor_loop"
213
- ) or pyfuncitem .funcargs .get ("loop" , None )
210
+ existing_loop = (
211
+ pyfuncitem .funcargs .get ("proactor_loop" )
212
+ or pyfuncitem .funcargs .get ("selector_loop" )
213
+ or pyfuncitem .funcargs .get ("uvloop_loop" )
214
+ or pyfuncitem .funcargs .get ("loop" , None )
215
+ )
216
+
214
217
with _runtime_warning_context ():
215
218
with _passthrough_loop_context (existing_loop , fast = fast ) as _loop :
216
219
testargs = {
@@ -227,11 +230,11 @@ def pytest_generate_tests(metafunc): # type: ignore[no-untyped-def]
227
230
return
228
231
229
232
loops = metafunc .config .option .aiohttp_loop
230
- avail_factories : Dict [str , Type [ asyncio .AbstractEventLoopPolicy ]]
231
- avail_factories = {"pyloop" : asyncio .DefaultEventLoopPolicy }
233
+ avail_factories : dict [str , Callable [[], asyncio .AbstractEventLoop ]]
234
+ avail_factories = {"pyloop" : asyncio .new_event_loop }
232
235
233
236
if uvloop is not None : # pragma: no cover
234
- avail_factories ["uvloop" ] = uvloop .EventLoopPolicy
237
+ avail_factories ["uvloop" ] = uvloop .new_event_loop
235
238
236
239
if loops == "all" :
237
240
loops = "pyloop,uvloop?"
@@ -255,23 +258,24 @@ def pytest_generate_tests(metafunc): # type: ignore[no-untyped-def]
255
258
256
259
257
260
@pytest .fixture
258
- def loop (loop_factory , fast , loop_debug ): # type: ignore[no-untyped-def]
261
+ def loop (
262
+ loop_factory : Callable [[], asyncio .AbstractEventLoop ],
263
+ fast : bool ,
264
+ loop_debug : bool ,
265
+ ) -> Iterator [asyncio .AbstractEventLoop ]:
259
266
"""Return an instance of the event loop."""
260
- policy = loop_factory ()
261
- asyncio .set_event_loop_policy (policy )
262
- with loop_context (fast = fast ) as _loop :
267
+ with loop_context (loop_factory , fast = fast ) as _loop :
263
268
if loop_debug :
264
269
_loop .set_debug (True ) # pragma: no cover
265
270
asyncio .set_event_loop (_loop )
266
271
yield _loop
267
272
268
273
269
274
@pytest .fixture
270
- def proactor_loop (): # type: ignore[no-untyped-def]
271
- policy = asyncio .WindowsProactorEventLoopPolicy () # type: ignore[attr-defined]
272
- asyncio .set_event_loop_policy (policy )
275
+ def proactor_loop () -> Iterator [asyncio .AbstractEventLoop ]:
276
+ factory = asyncio .ProactorEventLoop # type: ignore[attr-defined]
273
277
274
- with loop_context (policy . new_event_loop ) as _loop :
278
+ with loop_context (factory ) as _loop :
275
279
asyncio .set_event_loop (_loop )
276
280
yield _loop
277
281
0 commit comments