'Patch a function with a given return value, and return the mock'

def setup_patch(self, function_name, return_value):

    mock = MagicMock(return_value=return_value)
    new_patch = patch(function_name, new=mock)
    new_patch.start()
    self.addCleanup(new_patch.stop)
    return mock
