mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
#14533: if a test has no test_main, use loadTestsFromModule.
This moves us further in the direction of using normal unittest facilities instead of specialized regrtest ones. Any test module that can be correctly run currently using 'python unittest -m test.test_xxx' can now be converted to use normal unittest test loading by simply deleting its test_main, thus no longer requiring manual maintenance of the list of tests to run. (Not all tests can be converted that easily, since test_main sometimes does some additional things (such as reap_children or reap_threads). In those cases the extra code may be moved to setUpModule/tearDownModule methods, or perhaps the same ends can be achieved in a different way, such as moving the decorators to the test classes that need them, etc.) I don't advocate going through and making this change wholesale, but any time a list of tests in test_main would otherwise need to be updated, consideration should instead be given to deleting test_main.
This commit is contained in:
parent
b019ee752a
commit
78fc25c77f
3 changed files with 31 additions and 22 deletions
|
@ -1228,14 +1228,15 @@ def runtest_inner(test, verbose, quiet,
|
|||
start_time = time.time()
|
||||
the_package = __import__(abstest, globals(), locals(), [])
|
||||
the_module = getattr(the_package, test)
|
||||
# Old tests run to completion simply as a side-effect of
|
||||
# being imported. For tests based on unittest or doctest,
|
||||
# explicitly invoke their test_main() function (if it exists).
|
||||
indirect_test = getattr(the_module, "test_main", None)
|
||||
if indirect_test is not None:
|
||||
indirect_test()
|
||||
# If the test has a test_main, that will run the appropriate
|
||||
# tests. If not, use normal unittest test loading.
|
||||
test_runner = getattr(the_module, "test_main", None)
|
||||
if test_runner is None:
|
||||
tests = unittest.TestLoader().loadTestsFromModule(the_module)
|
||||
test_runner = lambda: support.run_unittest(tests)
|
||||
test_runner()
|
||||
if huntrleaks:
|
||||
refleak = dash_R(the_module, test, indirect_test,
|
||||
refleak = dash_R(the_module, test, test_runner,
|
||||
huntrleaks)
|
||||
test_time = time.time() - start_time
|
||||
except support.ResourceDenied as msg:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue