import inspect


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