Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8c0206

Browse files
committed
Issue #14637: Fix the UNC import test under Windows to actually use
the UNC path. Also clean up sys.path and invalidate finder caches. Thanks to Vinay Sajip for spotting the use of the wrong path.
1 parent 2f92389 commit b8c0206

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Lib/test/test_import.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,21 @@ def test_trailing_slash(self):
459459
def test_UNC_path(self):
460460
with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
461461
f.write("testdata = 'test_trailing_slash'")
462+
importlib.invalidate_caches()
462463
# Create the UNC path, like \\myhost\c$\foo\bar.
463464
path = os.path.abspath(self.path)
464465
import socket
465466
hn = socket.gethostname()
466467
drive = path[0]
467468
unc = "\\\\%s\\%s$"%(hn, drive)
468469
unc += path[2:]
469-
sys.path.append(path)
470-
mod = __import__("test_trailing_slash")
471-
self.assertEqual(mod.testdata, 'test_trailing_slash')
472-
unload("test_trailing_slash")
470+
sys.path.append(unc)
471+
try:
472+
mod = __import__("test_trailing_slash")
473+
self.assertEqual(mod.testdata, 'test_trailing_slash')
474+
unload("test_trailing_slash")
475+
finally:
476+
sys.path.remove(unc)
473477

474478

475479
class RelativeImportTests(unittest.TestCase):

0 commit comments

Comments
 (0)