mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Importlib was using custom code to discover all test modules in importlib.test.
This has now been removed in favor of using unittest's test discovery code in TestLoader.discover().
This commit is contained in:
parent
d8840860df
commit
b49c70c7d3
4 changed files with 21 additions and 37 deletions
|
@ -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'))
|
14
Lib/importlib/test/__main__.py
Normal file
14
Lib/importlib/test/__main__.py
Normal file
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue