]> granicus.if.org Git - python/commitdiff
Importlib was using custom code to discover all test modules in importlib.test.
authorBrett Cannon <bcannon@gmail.com>
Wed, 15 Jul 2009 04:08:33 +0000 (04:08 +0000)
committerBrett Cannon <bcannon@gmail.com>
Wed, 15 Jul 2009 04:08:33 +0000 (04:08 +0000)
This has now been removed in favor of using unittest's test discovery code in
TestLoader.discover().

Lib/importlib/test/__init__.py
Lib/importlib/test/__main__.py [new file with mode: 0644]
Lib/test/test_importlib.py
Misc/NEWS

index bda33e69fea2dc64876ec3d4b36ff33ce73c2d9a..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,31 +0,0 @@
-import os.path
-import sys
-import unittest
-
-
-def test_suite(package=__package__, directory=os.path.dirname(__file__)):
-    suite = unittest.TestSuite()
-    for name in os.listdir(directory):
-        if name.startswith('.'):
-            continue
-        path = os.path.join(directory, name)
-        if (os.path.isfile(path) and name.startswith('test_') and
-                name.endswith('.py')):
-            submodule_name = os.path.splitext(name)[0]
-            module_name = "{0}.{1}".format(package, submodule_name)
-            __import__(module_name, level=0)
-            module_tests = unittest.findTestCases(sys.modules[module_name])
-            suite.addTest(module_tests)
-        elif os.path.isdir(path):
-            package_name = "{0}.{1}".format(package, name)
-            __import__(package_name, level=0)
-            package_tests = getattr(sys.modules[package_name], 'test_suite')()
-            suite.addTest(package_tests)
-        else:
-            continue
-    return suite
-
-
-if __name__ == '__main__':
-    from test.support import run_unittest
-    run_unittest(test_suite('importlib.test'))
diff --git a/Lib/importlib/test/__main__.py b/Lib/importlib/test/__main__.py
new file mode 100644 (file)
index 0000000..d0710bd
--- /dev/null
@@ -0,0 +1,14 @@
+import os.path
+from test.support import run_unittest
+import unittest
+
+
+def test_main():
+    start_dir = os.path.dirname(__file__)
+    top_dir = os.path.dirname(os.path.dirname(start_dir))
+    test_loader = unittest.TestLoader()
+    run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
+
+
+if __name__ == '__main__':
+    test_main()
index cd13e329edd78bc079591486d14e42c4e1e5637d..6ed05859c934e106c68eb0f24b06dd8cb639a409 100644 (file)
@@ -1,9 +1,4 @@
-from test.support import run_unittest
-import importlib.test
-
-
-def test_main():
-    run_unittest(importlib.test.test_suite('importlib.test'))
+from importlib.test.__main__ import test_main
 
 
 if __name__ == '__main__':
index d44789e1308cde48a92dcd04715b96fc07571054..a740b33c7635cf0c20941e5b3521043419f6ccf3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -74,6 +74,12 @@ Build
 - Issue 5390: Add uninstall icon independent of whether file
   extensions are installed.
 
+Tests
+-----
+
+- Removed importlib's custom test discovery code and switched to
+    unittest.TestLoader.discover().
+
 
 What's New in Python 3.1?
 =========================