diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-12-05 13:58:36 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-05 13:58:36 (GMT) |
| commit | 5acfb8258afa1ecb445f699585ffbaf7529a640d (patch) | |
| tree | 12c99dc748510b9e6f8e6226505addfc99c2af6d /Lib/test | |
| parent | 68f05dd82976e0af4e3af0f65fe226d138ff55f7 (diff) | |
| download | cpython-5acfb8258afa1ecb445f699585ffbaf7529a640d.zip cpython-5acfb8258afa1ecb445f699585ffbaf7529a640d.tar.gz cpython-5acfb8258afa1ecb445f699585ffbaf7529a640d.tar.bz2 | |
[3.12] bpo-43153: Don't mask `PermissionError` with `NotADirectoryError` during tempdirectory cleanup (GH-29940) (GH-112753)
(cherry picked from commit 8cdfee1bb902fd1e38d79170b751ef13a0907262)
Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_tempfile.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 1673507..f4aef88 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1641,6 +1641,17 @@ class TestTemporaryDirectory(BaseTestCase): temp_path.exists(), f"TemporaryDirectory {temp_path!s} exists after cleanup") + @unittest.skipUnless(os.name == "nt", "Only on Windows.") + def test_explicit_cleanup_correct_error(self): + with tempfile.TemporaryDirectory() as working_dir: + temp_dir = self.do_create(dir=working_dir) + with open(os.path.join(temp_dir.name, "example.txt"), 'wb'): + # Previously raised NotADirectoryError on some OSes + # (e.g. Windows). See bpo-43153. + with self.assertRaises(PermissionError): + temp_dir.cleanup() + + @os_helper.skip_unless_symlink def test_cleanup_with_symlink_to_a_directory(self): # cleanup() should not follow symlinks to directories (issue #12464) |
