Kaydet (Commit) ab1c7918 authored tarafından Skip Montanaro's avatar Skip Montanaro

* 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.
üst 2850d186
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment