[Python-checkins] bpo-25094: Fix test_tools.test_sundry() on Windows (GH-8406) (GH-8407)

Victor Stinner webhook-mailer at python.org
Mon Jul 23 08:39:14 EDT 2018


https://github.com/python/cpython/commit/ba1810e1ec8973e48128e17845b981d8894c0550
commit: ba1810e1ec8973e48128e17845b981d8894c0550
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-07-23T14:39:11+02:00
summary:

bpo-25094: Fix test_tools.test_sundry() on Windows (GH-8406) (GH-8407)

When Python is installed on Windows, python -m test test_tools failed
because it tried to run Tools\scripts\2to3.py which requires an
argument. Skip this script. On other platforms or on Windows but when
run from source code (not installed), the script is called "2to3"
instead of "2to.py" and so was already skipped.

Modify also the unit test to unload all modules which have been
loaded by the test.
(cherry picked from commit 752d4b7531093c55d6f0a5846748f981d79b29d3)

Co-authored-by: Victor Stinner <vstinner at redhat.com>

files:
M Lib/test/test_tools/test_sundry.py

diff --git a/Lib/test/test_tools/test_sundry.py b/Lib/test/test_tools/test_sundry.py
index 2f9db9424f6f..f5fed01491e3 100644
--- a/Lib/test/test_tools/test_sundry.py
+++ b/Lib/test/test_tools/test_sundry.py
@@ -25,15 +25,25 @@ class TestSundryScripts(unittest.TestCase):
     # scripts that use windows-only modules
     windows_only = ['win_add2path']
     # blacklisted for other reasons
-    other = ['analyze_dxp']
+    other = ['analyze_dxp', '2to3']
 
     skiplist = blacklist + whitelist + windows_only + other
 
     def test_sundry(self):
-        for fn in os.listdir(scriptsdir):
-            name = fn[:-3]
-            if fn.endswith('.py') and name not in self.skiplist:
+        old_modules = support.modules_setup()
+        try:
+            for fn in os.listdir(scriptsdir):
+                if not fn.endswith('.py'):
+                    continue
+
+                name = fn[:-3]
+                if name in self.skiplist:
+                    continue
+
                 import_tool(name)
+        finally:
+            # Unload all modules loaded in this test
+            support.modules_cleanup(*old_modules)
 
     @unittest.skipIf(sys.platform != "win32", "Windows-only test")
     def test_sundry_windows(self):



More information about the Python-checkins mailing list