'Use python mock to mock an object attribute
Mocks the specified objects attribute with the given value.
Automatically performs \'addCleanup\' for the mock.'

def mock_object(self, obj, attr_name, *args, **kwargs):

    patcher = mock.patch.object(obj, attr_name, *args, **kwargs)
    result = patcher.start()
    self.addCleanup(patcher.stop)
    return result
