summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-04-20 19:52:17 (GMT)
committerBrett Cannon <brett@python.org>2012-04-20 19:52:17 (GMT)
commit1032af95ffc6ec1c288504dfd5321e941e3607d4 (patch)
tree0f42f7d938cf85a36ecaaa5f61f6f3d81d6b2904 /Lib/importlib
parent3dfc22cc048da44c21cb95996522696d8c679fc9 (diff)
downloadcpython-1032af95ffc6ec1c288504dfd5321e941e3607d4.zip
cpython-1032af95ffc6ec1c288504dfd5321e941e3607d4.tar.gz
cpython-1032af95ffc6ec1c288504dfd5321e941e3607d4.tar.bz2
Issue #14585: test_import now runs all tests under
importlib.test.import_ using builtins.__import__() instead of just the relative import tests.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/test/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/importlib/test/__init__.py b/Lib/importlib/test/__init__.py
index e69de29..815a706 100644
--- a/Lib/importlib/test/__init__.py
+++ b/Lib/importlib/test/__init__.py
@@ -0,0 +1,25 @@
+import os
+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