From 9b747c1d4fff31bd180b7fad8de46278e6d83b11 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 31 Aug 2026 15:46:51 +0300 Subject: [PATCH] gh-156707: Remove the junction created in test_realpath_volume_guid_path() The junction pointed to a volume without a mount point. It was left for the temporary directory cleanup, which descended into it and tried to remove files on that volume. os.rmdir() removes the junction itself, not the directory it points to. --- Lib/test/test_ntpath.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index a4de2c78f0bf0c..bc1dfe42164268 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -1585,11 +1585,15 @@ def test_realpath_volume_guid_path(self): except (OSError, subprocess.CalledProcessError): raise unittest.SkipTest('creating the test junction failed') - for path in 'testjunc', 'testjunc/spam', 'testjunc/spam/eggs': - with self.subTest(path=path): - realpath = ntpath.realpath(path) - self.assertStartsWith(realpath, '\\\\?\\Volume{') - self.assertTrue(ntpath.isabs(realpath), realpath) + try: + for path in 'testjunc', 'testjunc/spam', 'testjunc/spam/eggs': + with self.subTest(path=path): + realpath = ntpath.realpath(path) + self.assertStartsWith(realpath, '\\\\?\\Volume{') + self.assertTrue(ntpath.isabs(realpath), realpath) + finally: + # Remove the junction, not the volume it points to. + os_helper.rmdir('testjunc') def test_isfile_invalid_paths(self): isfile = ntpath.isfile