Issue #22806: Add ``python -m test --list-tests`` command to list tests.
This commit is contained in:
parent
076fc872bc
commit
5f9d3acc5e
|
@ -1,5 +1,4 @@
|
|||
import argparse
|
||||
import faulthandler
|
||||
import os
|
||||
from test import support
|
||||
|
||||
|
@ -234,6 +233,9 @@ def _create_parser():
|
|||
group.add_argument('-F', '--forever', action='store_true',
|
||||
help='run the specified tests in a loop, until an '
|
||||
'error happens')
|
||||
group.add_argument('--list-tests', action='store_true',
|
||||
help="only write the name of tests that will be run, "
|
||||
"don't execute them")
|
||||
|
||||
parser.add_argument('args', nargs=argparse.REMAINDER,
|
||||
help=argparse.SUPPRESS)
|
||||
|
@ -301,12 +303,7 @@ def _parse_args(args, **kwargs):
|
|||
if ns.quiet:
|
||||
ns.verbose = 0
|
||||
if ns.timeout is not None:
|
||||
if hasattr(faulthandler, 'dump_traceback_later'):
|
||||
if ns.timeout <= 0:
|
||||
ns.timeout = None
|
||||
else:
|
||||
print("Warning: The timeout option requires "
|
||||
"faulthandler.dump_traceback_later")
|
||||
if ns.timeout <= 0:
|
||||
ns.timeout = None
|
||||
if ns.use_mp is not None:
|
||||
if ns.use_mp <= 0:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import faulthandler
|
||||
import os
|
||||
import platform
|
||||
import random
|
||||
|
@ -110,8 +111,13 @@ class Regrtest:
|
|||
def parse_args(self, kwargs):
|
||||
ns = _parse_args(sys.argv[1:], **kwargs)
|
||||
|
||||
if ns.timeout and not hasattr(faulthandler, 'dump_traceback_later'):
|
||||
print("Warning: The timeout option requires "
|
||||
"faulthandler.dump_traceback_later", file=sys.stderr)
|
||||
ns.timeout = None
|
||||
|
||||
if ns.threshold is not None and gc is None:
|
||||
print('No GC available, ignore --threshold.')
|
||||
print('No GC available, ignore --threshold.', file=sys.stderr)
|
||||
ns.threshold = None
|
||||
|
||||
if ns.findleaks:
|
||||
|
@ -122,7 +128,8 @@ class Regrtest:
|
|||
pass
|
||||
#gc.set_debug(gc.DEBUG_SAVEALL)
|
||||
else:
|
||||
print('No GC available, disabling --findleaks')
|
||||
print('No GC available, disabling --findleaks',
|
||||
file=sys.stderr)
|
||||
ns.findleaks = False
|
||||
|
||||
# Strip .py extensions.
|
||||
|
@ -163,20 +170,6 @@ class Regrtest:
|
|||
nottests.add(arg)
|
||||
self.ns.args = []
|
||||
|
||||
# For a partial run, we do not need to clutter the output.
|
||||
if (self.ns.verbose
|
||||
or self.ns.header
|
||||
or not (self.ns.quiet or self.ns.single
|
||||
or self.tests or self.ns.args)):
|
||||
# Print basic platform information
|
||||
print("==", platform.python_implementation(), *sys.version.split())
|
||||
print("== ", platform.platform(aliased=True),
|
||||
"%s-endian" % sys.byteorder)
|
||||
print("== ", "hash algorithm:", sys.hash_info.algorithm,
|
||||
"64bit" if sys.maxsize > 2**32 else "32bit")
|
||||
print("== ", os.getcwd())
|
||||
print("Testing with flags:", sys.flags)
|
||||
|
||||
# if testdir is set, then we are not running the python tests suite, so
|
||||
# don't add default tests to be executed or skipped (pass empty values)
|
||||
if self.ns.testdir:
|
||||
|
@ -199,15 +192,18 @@ class Regrtest:
|
|||
del self.selected[:self.selected.index(self.ns.start)]
|
||||
except ValueError:
|
||||
print("Couldn't find starting test (%s), using all tests"
|
||||
% self.ns.start)
|
||||
% self.ns.start, file=sys.stderr)
|
||||
|
||||
if self.ns.randomize:
|
||||
if self.ns.random_seed is None:
|
||||
self.ns.random_seed = random.randrange(10000000)
|
||||
random.seed(self.ns.random_seed)
|
||||
print("Using random seed", self.ns.random_seed)
|
||||
random.shuffle(self.selected)
|
||||
|
||||
def list_tests(self):
|
||||
for name in self.selected:
|
||||
print(name)
|
||||
|
||||
def rerun_failed_tests(self):
|
||||
self.ns.verbose = True
|
||||
self.ns.failfast = False
|
||||
|
@ -315,6 +311,23 @@ class Regrtest:
|
|||
return
|
||||
|
||||
def run_tests(self):
|
||||
# For a partial run, we do not need to clutter the output.
|
||||
if (self.ns.verbose
|
||||
or self.ns.header
|
||||
or not (self.ns.quiet or self.ns.single
|
||||
or self.tests or self.ns.args)):
|
||||
# Print basic platform information
|
||||
print("==", platform.python_implementation(), *sys.version.split())
|
||||
print("== ", platform.platform(aliased=True),
|
||||
"%s-endian" % sys.byteorder)
|
||||
print("== ", "hash algorithm:", sys.hash_info.algorithm,
|
||||
"64bit" if sys.maxsize > 2**32 else "32bit")
|
||||
print("== ", os.getcwd())
|
||||
print("Testing with flags:", sys.flags)
|
||||
|
||||
if self.ns.randomize:
|
||||
print("Using random seed", self.ns.random_seed)
|
||||
|
||||
if self.ns.forever:
|
||||
self.tests = self._test_forever(list(self.selected))
|
||||
self.test_count = ''
|
||||
|
@ -359,8 +372,12 @@ class Regrtest:
|
|||
setup_tests(self.ns)
|
||||
|
||||
self.find_tests(tests)
|
||||
self.run_tests()
|
||||
|
||||
if self.ns.list_tests:
|
||||
self.list_tests()
|
||||
sys.exit(0)
|
||||
|
||||
self.run_tests()
|
||||
self.display_result()
|
||||
|
||||
if self.ns.verbose2 and self.bad:
|
||||
|
|
|
@ -672,6 +672,13 @@ class ArgsTestCase(BaseTestCase):
|
|||
reflog = fp.read()
|
||||
self.assertEqual(reflog, line2)
|
||||
|
||||
def test_list_tests(self):
|
||||
# test --list-tests
|
||||
tests = [self.create_test() for i in range(5)]
|
||||
output = self.run_tests('--list-tests', *tests)
|
||||
self.assertEqual(output.rstrip().splitlines(),
|
||||
tests)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue