File tree Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Expand file tree Collapse file tree 2 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 19
19
# Only available in Python 3.4+ or as a backport
20
20
enum = None
21
21
22
- try :
23
- import asyncio
24
- except ImportError : # pragma: no cover
25
- # Only available in Python 3.4+ or as a backport
26
- asyncio = None
27
22
28
23
_PY3 = sys .version_info > (3 , 0 )
29
24
_PY2 = not _PY3
@@ -49,9 +44,17 @@ def _format_args(func):
49
44
50
45
def is_generator (func ):
51
46
genfunc = inspect .isgeneratorfunction (func )
52
- if asyncio is not None :
53
- return genfunc and not asyncio .iscoroutinefunction (func )
54
- return genfunc
47
+ return genfunc and not iscoroutinefunction (func )
48
+
49
+
50
+ def iscoroutinefunction (func ):
51
+ """Return True if func is a decorated coroutine function.
52
+
53
+ Note: copied and modified from Python 3.5's builtin couroutines.py to avoid import asyncio directly,
54
+ which in turns also initializes the "logging" module as side-effect (see issue #8).
55
+ """
56
+ return (getattr (func , '_is_coroutine' , False ) or
57
+ (hasattr (inspect , 'iscoroutinefunction' ) and inspect .iscoroutinefunction (func )))
55
58
56
59
57
60
def getlocation (function , curdir ):
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ def foo():
15
15
assert not is_generator (foo )
16
16
17
17
18
+ @pytest .mark .skipif (sys .version_info < (3 , 4 ), reason = 'asyncio available in Python 3.4+' )
18
19
def test_is_generator_asyncio (testdir ):
19
- pytest .importorskip ('asyncio' )
20
20
testdir .makepyfile ("""
21
21
from _pytest.compat import is_generator
22
22
import asyncio
@@ -27,7 +27,8 @@ def baz():
27
27
def test_is_generator_asyncio():
28
28
assert not is_generator(baz)
29
29
""" )
30
- result = testdir .runpytest ()
30
+ # avoid importing asyncio into pytest's own process, which in turn imports logging (#8)
31
+ result = testdir .runpytest_subprocess ()
31
32
result .stdout .fnmatch_lines (['*1 passed*' ])
32
33
33
34
You can’t perform that action at this time.
0 commit comments