@contextmanager<EOL>def chdir(path):
if path is None:<EOL><INDENT>yield<EOL><DEDENT>else:<EOL><INDENT>old_dir = os.getcwd()<EOL>os.chdir(path)<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(old_dir)<EOL><DEDENT><DEDENT>
Change working directory to `path` and restore old path on exit.

    `path` can be `None` in which case this is a no-op.