summaryrefslogtreecommitdiff
path: root/_pytest/compat.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2016-12-13 21:54:20 -0200
committerBruno Oliveira <nicoddemus@gmail.com>2016-12-13 21:54:20 -0200
commitcaee5ce489e4f7058154bea1b4bc371bd384af20 (patch)
tree86a8b5d3db2dedc952b18aa3824f29d96ed5dc49 /_pytest/compat.py
parent1312b83866709611aaa9d9d22e3161dfd9b8d244 (diff)
downloadpytest-caee5ce489e4f7058154bea1b4bc371bd384af20.tar.gz
Avoid importing asyncio directly because that in turn initializes logging (#8)
Diffstat (limited to '_pytest/compat.py')
-rw-r--r--_pytest/compat.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/_pytest/compat.py b/_pytest/compat.py
index 7a3d0af81..dc3e69545 100644
--- a/_pytest/compat.py
+++ b/_pytest/compat.py
@@ -19,11 +19,6 @@ except ImportError: # pragma: no cover
# Only available in Python 3.4+ or as a backport
enum = None
-try:
- import asyncio
-except ImportError: # pragma: no cover
- # Only available in Python 3.4+ or as a backport
- asyncio = None
_PY3 = sys.version_info > (3, 0)
_PY2 = not _PY3
@@ -49,9 +44,17 @@ REGEX_TYPE = type(re.compile(''))
def is_generator(func):
genfunc = inspect.isgeneratorfunction(func)
- if asyncio is not None:
- return genfunc and not asyncio.iscoroutinefunction(func)
- return genfunc
+ return genfunc and not iscoroutinefunction(func)
+
+
+def iscoroutinefunction(func):
+ """Return True if func is a decorated coroutine function.
+
+ Note: copied and modified from Python 3.5's builtin couroutines.py to avoid import asyncio directly,
+ which in turns also initializes the "logging" module as side-effect (see issue #8).
+ """
+ return (getattr(func, '_is_coroutine', False) or
+ (hasattr(inspect, 'iscoroutinefunction') and inspect.iscoroutinefunction(func)))
def getlocation(function, curdir):