Issue #22002: Make full use of test discovery in test sub-packages.

Adds `load_package_tests` function to test.support, uses it in test_asyncio,
test_email, test_json, test_tools, test_importlib and all test_importlib
sub-packages to implement test discovery.
This commit is contained in:
Zachary Ware 2014-07-23 12:00:29 -05:00
parent c4c464911a
commit f012ba42fe
21 changed files with 104 additions and 169 deletions

View file

@ -1,29 +1,10 @@
import os
import sys
import unittest
from test.support import run_unittest, import_module
from test.support import load_package_tests, import_module
# Skip tests if we don't have threading.
import_module('threading')
# Skip tests if we don't have concurrent.futures.
import_module('concurrent.futures')
def suite():
tests = unittest.TestSuite()
loader = unittest.TestLoader()
for fn in os.listdir(os.path.dirname(__file__)):
if fn.startswith("test") and fn.endswith(".py"):
mod_name = 'test.test_asyncio.' + fn[:-3]
try:
__import__(mod_name)
except unittest.SkipTest:
pass
else:
mod = sys.modules[mod_name]
tests.addTests(loader.loadTestsFromModule(mod))
return tests
def test_main():
run_unittest(suite())
def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)

View file

@ -1,5 +1,4 @@
from . import test_main
from . import load_tests
import unittest
if __name__ == '__main__':
test_main()
unittest.main()