'Convenient wrapper around `mock.patch.object`
Returns a started mock that will be automatically stopped after the
test ran.'

def patchobject(self, target, attribute, new=mock.DEFAULT):

    p = mock.patch.object(target, attribute, new)
    m = p.start()
    self.addCleanup(p.stop)
    return m
