[3.12] gh-79325: Fix recursion error in TemporaryDirectory cleanup on Windows (GH-112762) (GH-112847)

(cherry picked from commit b2923a61a1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-12-07 18:36:29 +01:00 committed by GitHub
parent 418adf687f
commit 34e9e20cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View file

@ -1651,6 +1651,17 @@ class TestTemporaryDirectory(BaseTestCase):
with self.assertRaises(PermissionError):
temp_dir.cleanup()
@unittest.skipUnless(os.name == "nt", "Only on Windows.")
def test_cleanup_with_used_directory(self):
with tempfile.TemporaryDirectory() as working_dir:
temp_dir = self.do_create(dir=working_dir)
subdir = os.path.join(temp_dir.name, "subdir")
os.mkdir(subdir)
with os_helper.change_cwd(subdir):
# Previously raised RecursionError on some OSes
# (e.g. Windows). See bpo-35144.
with self.assertRaises(PermissionError):
temp_dir.cleanup()
@os_helper.skip_unless_symlink
def test_cleanup_with_symlink_to_a_directory(self):