diff options
author | Skip Montanaro <skip@pobox.com> | 2000-06-30 16:39:27 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2000-06-30 16:39:27 (GMT) |
commit | ab1c7918f683e540ae5651c1b585ecda16ae352d (patch) | |
tree | ca8b0de96f30eece1816e684c6a795780f25a6b1 /Lib | |
parent | 2850d186156ca4af83a298d24fa7e96af9f4807c (diff) | |
download | cpython-ab1c7918f683e540ae5651c1b585ecda16ae352d.zip cpython-ab1c7918f683e540ae5651c1b585ecda16ae352d.tar.gz cpython-ab1c7918f683e540ae5651c1b585ecda16ae352d.tar.bz2 |
* added a randomize flag and corresponding -r command line argument that
allows the caller to execute the various tests in pseudo-random order -
default is still to execute tests in the order returned by findtests().
* moved initialization of the various flag variables to the main() function
definition, making it possible to execute regrtest.main() interactively
and still override default behavior.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/test/regrtest.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 86b3d9a..27b2b03 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -13,6 +13,7 @@ Command line options: -g: generate -- write the output file for a test instead of comparing it -x: exclude -- arguments are tests to *exclude* -s: single -- run only a single test (see below) +-r: random -- randomize test execution order If non-option arguments are present, they are names for tests to run, unless -x is given, in which case they are names for tests not to run. @@ -33,10 +34,12 @@ import string import os import getopt import traceback +import random import test_support -def main(tests=None, testdir=None): +def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, + exclude=0, single=0, randomize=0): """Execute a test suite. This also parses command-line options and modifies its behaviour @@ -52,26 +55,26 @@ def main(tests=None, testdir=None): If the tests argument is omitted, the tests listed on the command-line will be used. If that's empty, too, then all *.py files beginning with test_ will be used. - + + The other six default arguments (verbose, quiet, generate, exclude, + single, and randomize) allow programmers calling main() directly to + set the values that would normally be set by flags on the command + line. """ try: - opts, args = getopt.getopt(sys.argv[1:], 'vgqxs') + opts, args = getopt.getopt(sys.argv[1:], 'vgqxsr') except getopt.error, msg: print msg print __doc__ return 2 - verbose = 0 - quiet = 0 - generate = 0 - exclude = 0 - single = 0 for o, a in opts: if o == '-v': verbose = verbose+1 if o == '-q': quiet = 1; verbose = 0 if o == '-g': generate = 1 if o == '-x': exclude = 1 if o == '-s': single = 1 + if o == '-r': randomize = 1 if generate and verbose: print "-g and -v don't go together!" return 2 @@ -104,6 +107,8 @@ def main(tests=None, testdir=None): tests = tests or args or findtests(testdir, stdtests, nottests) if single: tests = tests[:1] + if randomize: + random.shuffle(tests) test_support.verbose = verbose # Tell tests to be moderately quiet save_modules = sys.modules.keys() for test in tests: |