Replays calls to a method located at import_path. These calls must occur after the start of a method for which there is a cache hit. E.g. after a method patched with patch() or cached with cache()

    :param str import_path: The absolute import path for the method to monitor and replay as a string.

    :rtype: function
    :returns: The decorated method with all existing references to the target replaced with a recorder to replay it

def replay(import_path):
    """
    Replays calls to a method located at import_path. These calls must occur after the start of a method for which there is a cache hit. E.g. after a method patched with patch() or cached with cache()

    :param str import_path: The absolute import path for the method to monitor and replay as a string.

    :rtype: function
    :returns: The decorated method with all existing references to the target replaced with a recorder to replay it
    """
    def patch_method(unpatched_method):
        context = get_context(unpatched_method)

        recorder = get_recorder(import_path, context)

        @patch(import_path, side_effect=recorder, ctxt=context)
        def patched_method(*args, **kwargs):
            try:
                return unpatched_method(*args, **kwargs)
            finally:
                context.exit()

        patched_method.__context = context
        return patched_method
    return patch_method