def method_mock(request, cls, method_name, **kwargs):
 _patch = patch.object(cls, method_name, **kwargs)
 request.addfinalizer(_patch.stop)
 return _patch.start()

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