File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 # Only available in Python 3.4+ or as a backport
2020 enum = None
2121
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
2722
2823_PY3 = sys .version_info > (3 , 0 )
2924_PY2 = not _PY3
@@ -49,9 +44,17 @@ def _format_args(func):
4944
5045def is_generator (func ):
5146 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 )))
5558
5659
5760def getlocation (function , curdir ):
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ def foo():
1515 assert not is_generator (foo )
1616
1717
18+ @pytest .mark .skipif (sys .version_info < (3 , 4 ), reason = 'asyncio available in Python 3.4+' )
1819def test_is_generator_asyncio (testdir ):
19- pytest .importorskip ('asyncio' )
2020 testdir .makepyfile ("""
2121 from _pytest.compat import is_generator
2222 import asyncio
@@ -27,7 +27,8 @@ def baz():
2727 def test_is_generator_asyncio():
2828 assert not is_generator(baz)
2929 """ )
30- result = testdir .runpytest ()
30+ # avoid importing asyncio into pytest's own process, which in turn imports logging (#8)
31+ result = testdir .runpytest_subprocess ()
3132 result .stdout .fnmatch_lines (['*1 passed*' ])
3233
3334
You can’t perform that action at this time.
0 commit comments