import inspect


def _is_context_manager(func):
    """
    Detect if the given method or function is decorated with @contextmanager.

    Parameters
    ----------
    func : function or method
        The function or method to be tested.

    Returns
    -------
    bool
        True if the function or method is has the @contextmanager decorator,
        otherwise False.

    """
    src = inspect.getsource(func).lstrip()
    return 'return GeneratorContextManager' in src or src.startswith('@contextmanager')