def chdir(path):
    """Change the working directory to `path` for the duration of this context
    manager.

    :param str path: The path to change to
    """
    cur_cwd = os.getcwd()
    os.chdir(path)
    try:
        yield
    finally:
        os.chdir(cur_cwd)