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

(cherry picked from commit b2923a61a1)
This commit is contained in:
Serhiy Storchaka 2023-12-07 19:46:30 +02:00 committed by GitHub
parent 5585334d77
commit a18201bff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View file

@ -1543,6 +1543,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):