'Use python mock to mock a path with automatic cleanup.'

def patch(self, path, *args, **kwargs):

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