from unittest.mock import patch


def method_mock(cls, method_name, request):
    """
    Return a mock for method *method_name* on *cls* where the patch is
    reversed after pytest uses it.
    """
    _patch = patch.object(cls, method_name)
    request.addfinalizer(_patch.stop)
    return _patch.start()