mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #14585: test_import now runs all tests under
importlib.test.import_ using builtins.__import__() instead of just the relative import tests.
This commit is contained in:
parent
3dfc22cc04
commit
1032af95ff
2 changed files with 35 additions and 15 deletions
|
@ -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
|
|
@ -1,6 +1,6 @@
|
||||||
import builtins
|
import builtins
|
||||||
import imp
|
import imp
|
||||||
from importlib.test.import_ import test_relative_imports
|
from importlib.test.import_ import test_suite as importlib_import_test_suite
|
||||||
from importlib.test.import_ import util as importlib_util
|
from importlib.test.import_ import util as importlib_util
|
||||||
import importlib
|
import importlib
|
||||||
import marshal
|
import marshal
|
||||||
|
@ -694,21 +694,16 @@ class PycacheTests(unittest.TestCase):
|
||||||
self.assertEqual(m.x, 5)
|
self.assertEqual(m.x, 5)
|
||||||
|
|
||||||
|
|
||||||
class RelativeImportFromImportlibTests(test_relative_imports.RelativeImports):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self._importlib_util_flag = importlib_util.using___import__
|
|
||||||
importlib_util.using___import__ = True
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
importlib_util.using___import__ = self._importlib_util_flag
|
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
run_unittest(ImportTests, PycacheTests,
|
flag = importlib_util.using___import__
|
||||||
PycRewritingTests, PathsTests, RelativeImportTests,
|
try:
|
||||||
OverridingImportBuiltinTests,
|
importlib_util.using___import__ = True
|
||||||
RelativeImportFromImportlibTests)
|
run_unittest(ImportTests, PycacheTests,
|
||||||
|
PycRewritingTests, PathsTests, RelativeImportTests,
|
||||||
|
OverridingImportBuiltinTests,
|
||||||
|
importlib_import_test_suite())
|
||||||
|
finally:
|
||||||
|
importlib_util.using___import__ = flag
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue