@@ -27,30 +27,21 @@ def pytest_pycollect_makeitem(collector, name, obj):
27
27
return list (collector ._genfunctions (name , obj ))
28
28
29
29
30
- def _argnames (func ):
31
- spec = inspect .getfullargspec (func )
32
- if spec .defaults :
33
- return spec .args [:- len (spec .defaults )]
34
- return spec .args
35
-
36
-
37
30
@pytest .mark .tryfirst
38
31
def pytest_pyfunc_call (pyfuncitem ):
39
- """A hook wrapper."""
40
- if 'asyncio_process_pool' in pyfuncitem .keywords :
41
- event_loop = pyfuncitem .funcargs .get ('event_loop_process_pool' )
42
- funcargs = dict ((arg , pyfuncitem .funcargs [arg ])
43
- for arg in _argnames (pyfuncitem .obj ))
44
- event_loop .run_until_complete (asyncio .async (pyfuncitem .obj (** funcargs )))
45
- # prevent other pyfunc calls from executing
46
- return True
47
- elif 'asyncio' in pyfuncitem .keywords :
48
- event_loop = pyfuncitem .funcargs .get ('event_loop' )
49
- funcargs = dict ((arg , pyfuncitem .funcargs [arg ])
50
- for arg in _argnames (pyfuncitem .obj ))
51
- event_loop .run_until_complete (asyncio .async (pyfuncitem .obj (** funcargs )))
52
- # prevent other pyfunc calls from executing
53
- return True
32
+ """
33
+ Run asyncio marked test functions in an event loop instead of a normal
34
+ function call.
35
+ """
36
+ for fixture_name in ('asyncio_process_pool' , 'asyncio' ):
37
+ if fixture_name in pyfuncitem .funcargs :
38
+ event_loop = pyfuncitem .funcargs [fixture_name ]
39
+ funcargs = pyfuncitem .funcargs
40
+ testargs = {(arg , funcargs [arg ])
41
+ for arg in pyfuncitem ._fixtureinfo .argnames }
42
+ event_loop .run_until_complete (
43
+ asyncio .async (pyfuncitem .obj (** testargs )))
44
+ return True
54
45
55
46
56
47
def pytest_runtest_setup (item ):
0 commit comments