Eryk Sun <[email protected]> added the comment:
> def test_chdir():
> with tempfile.TemporaryDirectory() as tempdir:
> old = os.getcwd()
> os.chdir(tempdir)
> with open(os.path.join(tempdir, "delme")) as fout:
> fout.write("Hello")
> os.chdir(old)
The open() call in test_chdir() fails before os.chdir(old) executes. You would
need to call os.chdir(old) in a `finally` block.
But the cleanup routine could still fail due to a sharing violation from some
other process (likely a child process) setting the directory or a child
directory as the working directory. Also, a sharing violation when trying to
delete a regular file in the tree causes the cleanup routine to fail with
NotADirectoryError because the onerror function calls rmtree() if unlink()
fails with a PermissionError.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42796>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com