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