summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2023-12-05 13:30:59 (GMT)
committerGitHub <noreply@github.com>2023-12-05 13:30:59 (GMT)
commit8cdfee1bb902fd1e38d79170b751ef13a0907262 (patch)
treee5476cbdd925cd354e014610ba7050120769ad1a /Lib/test/test_tempfile.py
parent5aa317e4ca619c3735e1d67b507f01a8e49a4c49 (diff)
downloadcpython-8cdfee1bb902fd1e38d79170b751ef13a0907262.zip
cpython-8cdfee1bb902fd1e38d79170b751ef13a0907262.tar.gz
cpython-8cdfee1bb902fd1e38d79170b751ef13a0907262.tar.bz2
bpo-43153: Don't mask `PermissionError` with `NotADirectoryError` during tempdirectory cleanup (GH-29940)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py11
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)