'A context manager that creates a temporary folder and changes
the current working directory to it for isolated filesystem tests.'

@contextlib.contextmanager
def isolated_filesystem(self):

    cwd = os.getcwd()
    t = tempfile.mkdtemp()
    os.chdir(t)
    try:
        (yield t)
    finally:
        os.chdir(cwd)
        try:
            shutil.rmtree(t)
        except (OSError, IOError):
            pass
