bpo-25094: Fix test_tools.test_sundry() on Windows (GH-8406) (GH-8407) · python/cpython@ba1810e (original) (raw)

Original file line number Diff line number Diff line change
@@ -25,15 +25,25 @@ class TestSundryScripts(unittest.TestCase):
25 25 # scripts that use windows-only modules
26 26 windows_only = ['win_add2path']
27 27 # blacklisted for other reasons
28 -other = ['analyze_dxp']
28 +other = ['analyze_dxp', '2to3']
29 29
30 30 skiplist = blacklist + whitelist + windows_only + other
31 31
32 32 def test_sundry(self):
33 -for fn in os.listdir(scriptsdir):
34 -name = fn[:-3]
35 -if fn.endswith('.py') and name not in self.skiplist:
33 +old_modules = support.modules_setup()
34 +try:
35 +for fn in os.listdir(scriptsdir):
36 +if not fn.endswith('.py'):
37 +continue
38 +
39 +name = fn[:-3]
40 +if name in self.skiplist:
41 +continue
42 +
36 43 import_tool(name)
44 +finally:
45 +# Unload all modules loaded in this test
46 +support.modules_cleanup(*old_modules)
37 47
38 48 @unittest.skipIf(sys.platform != "win32", "Windows-only test")
39 49 def test_sundry_windows(self):