From f6fd413b32398bc181650cdaf712d5f2981dfc85 Mon Sep 17 00:00:00 2001 From: Paul Kienzle Date: Wed, 7 Feb 2018 12:41:04 -0500 Subject: [PATCH] pytest: is_generator is not part of public api, so reimplement it in conftest --- conftest.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 97ec3c408..9346af472 100644 --- a/conftest.py +++ b/conftest.py @@ -16,10 +16,10 @@ from __future__ import print_function import os.path +import inspect import pytest from _pytest.unittest import TestCaseFunction -from _pytest.compat import is_generator def pytest_pycollect_makeitem(collector, name, obj): """ @@ -55,6 +55,17 @@ def build_test(test, value): tests.append(test) return tests +def is_generator(func): + """ + Returns True if function has yield. + """ + # Cribbed from _pytest.compat is_generator and iscoroutinefunction; these + # may not be available as part of pytest 4. + coroutine = (getattr(func, '_is_coroutine', False) or + getattr(inspect, 'iscoroutinefunction', lambda f: False)(func)) + generator = inspect.isgeneratorfunction(func) + return generator and not coroutine + def split_yielded_test(obj, number): if not isinstance(obj, (tuple, list)): obj = (obj,)