35
35
Class ,
36
36
Collector ,
37
37
Config ,
38
+ FixtureDef ,
38
39
FixtureRequest ,
39
40
Function ,
40
41
Item ,
62
63
FixtureFunction = Union [SimpleFixtureFunction , FactoryFixtureFunction ]
63
64
FixtureFunctionMarker = Callable [[FixtureFunction ], FixtureFunction ]
64
65
65
- # https://github.com/pytest-dev/pytest/commit/fb55615d5e999dd44306596f340036c195428ef1
66
- if pytest .version_tuple < (8 , 0 ):
67
- FixtureDef = Any
68
- else :
69
- from pytest import FixtureDef
70
-
71
66
72
67
class PytestAsyncioError (Exception ):
73
68
"""Base class for exceptions raised by pytest-asyncio"""
@@ -320,8 +315,7 @@ def _wrap_asyncgen_fixture(fixturedef: FixtureDef) -> None:
320
315
321
316
@functools .wraps (fixture )
322
317
def _asyncgen_fixture_wrapper (request : FixtureRequest , ** kwargs : Any ):
323
- unittest = fixturedef .unittest if hasattr (fixturedef , "unittest" ) else False
324
- func = _perhaps_rebind_fixture_func (fixture , request .instance , unittest )
318
+ func = _perhaps_rebind_fixture_func (fixture , request .instance , False )
325
319
event_loop_fixture_id = _get_event_loop_fixture_id_for_async_fixture (
326
320
request , func
327
321
)
@@ -330,15 +324,15 @@ def _asyncgen_fixture_wrapper(request: FixtureRequest, **kwargs: Any):
330
324
gen_obj = func (** _add_kwargs (func , kwargs , event_loop , request ))
331
325
332
326
async def setup ():
333
- res = await gen_obj .__anext__ ()
327
+ res = await gen_obj .__anext__ () # type: ignore[union-attr]
334
328
return res
335
329
336
330
def finalizer () -> None :
337
331
"""Yield again, to finalize."""
338
332
339
333
async def async_finalizer () -> None :
340
334
try :
341
- await gen_obj .__anext__ ()
335
+ await gen_obj .__anext__ () # type: ignore[union-attr]
342
336
except StopAsyncIteration :
343
337
pass
344
338
else :
@@ -352,16 +346,15 @@ async def async_finalizer() -> None:
352
346
request .addfinalizer (finalizer )
353
347
return result
354
348
355
- fixturedef .func = _asyncgen_fixture_wrapper
349
+ fixturedef .func = _asyncgen_fixture_wrapper # type: ignore[misc]
356
350
357
351
358
352
def _wrap_async_fixture (fixturedef : FixtureDef ) -> None :
359
353
fixture = fixturedef .func
360
354
361
355
@functools .wraps (fixture )
362
356
def _async_fixture_wrapper (request : FixtureRequest , ** kwargs : Any ):
363
- unittest = False if pytest .version_tuple >= (8 , 2 ) else fixturedef .unittest
364
- func = _perhaps_rebind_fixture_func (fixture , request .instance , unittest )
357
+ func = _perhaps_rebind_fixture_func (fixture , request .instance , False )
365
358
event_loop_fixture_id = _get_event_loop_fixture_id_for_async_fixture (
366
359
request , func
367
360
)
@@ -374,7 +367,7 @@ async def setup():
374
367
375
368
return event_loop .run_until_complete (setup ())
376
369
377
- fixturedef .func = _async_fixture_wrapper
370
+ fixturedef .func = _async_fixture_wrapper # type: ignore[misc]
378
371
379
372
380
373
def _get_event_loop_fixture_id_for_async_fixture (
0 commit comments