'Utilility function to mock object\'s attribute at runtime:
Some methods are dynamic, so standard mocking does not work
and we need to mock them at runtime.
e.g. self._session.VIF.get_record which is dynamically
created via the override function of __getattr__.'

def mock_patch_object(self, target, attribute, return_val=None, side_effect=None):

    patcher = mock.patch.object(target, attribute, return_value=return_val, side_effect=side_effect)
    mock_one = patcher.start()
    self.addCleanup(patcher.stop)
    return mock_one
