diff options
author | Ken Jin <kenjin@python.org> | 2023-12-05 13:30:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-05 13:30:59 (GMT) |
commit | 8cdfee1bb902fd1e38d79170b751ef13a0907262 (patch) | |
tree | e5476cbdd925cd354e014610ba7050120769ad1a /Lib/test/test_tempfile.py | |
parent | 5aa317e4ca619c3735e1d67b507f01a8e49a4c49 (diff) | |
download | cpython-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.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) |