mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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:
parent
c4c464911a
commit
f012ba42fe
21 changed files with 104 additions and 169 deletions
|
@ -1,33 +1,5 @@
|
|||
import os
|
||||
import sys
|
||||
from test import support
|
||||
import unittest
|
||||
from test.support import load_package_tests
|
||||
|
||||
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
|
||||
|
||||
|
||||
def test_main():
|
||||
start_dir = os.path.dirname(__file__)
|
||||
top_dir = os.path.dirname(os.path.dirname(start_dir))
|
||||
test_loader = unittest.TestLoader()
|
||||
support.run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
"""Run importlib's test suite.
|
||||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
Specifying the ``--builtin`` flag will run tests, where applicable, with
|
||||
builtins.__import__ instead of importlib.__import__.
|
||||
|
||||
"""
|
||||
if __name__ == '__main__':
|
||||
from . import test_main
|
||||
test_main()
|
||||
unittest.main()
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
from .. import test_suite
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def test_suite():
|
||||
directory = os.path.dirname(__file__)
|
||||
return test_suite('importlib.test.builtin', directory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from test.support import run_unittest
|
||||
run_unittest(test_suite())
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
4
Lib/test/test_importlib/builtin/__main__.py
Normal file
4
Lib/test/test_importlib/builtin/__main__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
|
@ -1,13 +1,5 @@
|
|||
from .. import test_suite
|
||||
import os.path
|
||||
import unittest
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def test_suite():
|
||||
directory = os.path.dirname(__file__)
|
||||
return test_suite('importlib.test.extension', directory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from test.support import run_unittest
|
||||
run_unittest(test_suite())
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
4
Lib/test/test_importlib/extension/__main__.py
Normal file
4
Lib/test/test_importlib/extension/__main__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
|
@ -1,13 +1,5 @@
|
|||
from .. import test_suite
|
||||
import os.path
|
||||
import unittest
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def test_suite():
|
||||
directory = os.path.dirname(__file__)
|
||||
return test_suite('importlib.test.frozen', directory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from test.support import run_unittest
|
||||
run_unittest(test_suite())
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
4
Lib/test/test_importlib/frozen/__main__.py
Normal file
4
Lib/test/test_importlib/frozen/__main__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
|
@ -1,13 +1,5 @@
|
|||
from .. import test_suite
|
||||
import os.path
|
||||
import unittest
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def test_suite():
|
||||
directory = os.path.dirname(__file__)
|
||||
return test_suite('importlib.test.import_', directory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from test.support import run_unittest
|
||||
run_unittest(test_suite())
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
4
Lib/test/test_importlib/import_/__main__.py
Normal file
4
Lib/test/test_importlib/import_/__main__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
|
@ -1,13 +1,5 @@
|
|||
from .. import test_suite
|
||||
import os.path
|
||||
import unittest
|
||||
import os
|
||||
from test.support import load_package_tests
|
||||
|
||||
|
||||
def test_suite():
|
||||
directory = os.path.dirname(__file__)
|
||||
return test.test_suite('importlib.test.source', directory)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from test.support import run_unittest
|
||||
run_unittest(test_suite())
|
||||
def load_tests(*args):
|
||||
return load_package_tests(os.path.dirname(__file__), *args)
|
||||
|
|
4
Lib/test/test_importlib/source/__main__.py
Normal file
4
Lib/test/test_importlib/source/__main__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from . import load_tests
|
||||
import unittest
|
||||
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue