Message384172
> 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. |
|
Date |
User |
Action |
Args |
2021-01-01 14:27:04 | eryksun | set | recipients:
+ eryksun, christian.heimes, Gabriele Tornetta |
2021-01-01 14:27:04 | eryksun | set | messageid: <1609511224.2.0.133035718092.issue42796@roundup.psfhosted.org> |
2021-01-01 14:27:04 | eryksun | link | issue42796 messages |
2021-01-01 14:27:04 | eryksun | create | |
|