def METHOD_NAME(path):
    """Context manager that restores PWD even if an exception was raised."""
    old_pwd = os.getcwd()
    os.chdir(str(path))
    try:
        yield
    finally:
        os.chdir(old_pwd)