This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Gabriele Tornetta, christian.heimes, eryksun
Date 2021-01-01.14:27:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1609511224.2.0.133035718092.issue42796@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2021-01-01 14:27:04eryksunsetrecipients: + eryksun, christian.heimes, Gabriele Tornetta
2021-01-01 14:27:04eryksunsetmessageid: <1609511224.2.0.133035718092.issue42796@roundup.psfhosted.org>
2021-01-01 14:27:04eryksunlinkissue42796 messages
2021-01-01 14:27:04eryksuncreate