Skip to content

Commit

Permalink
pytest: is_generator is not part of public api, so reimplement it in …
Browse files Browse the repository at this point in the history
…conftest
  • Loading branch information
Paul Kienzle committed Feb 7, 2018
1 parent b4272a2 commit f6fd413
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion conftest.py
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,)
Expand Down

0 comments on commit f6fd413

Please sign in to comment.