Add -s/--start option that makes it easier to run the tests in batches

when one test fails and you want to start running from that point onwards.
This commit is contained in:
Neal Norwitz 2007-08-12 01:31:40 +00:00
parent dcb46eda32
commit 801c89be5d
1 changed files with 19 additions and 3 deletions

View File

@ -15,6 +15,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)
-S: start -- start running all the tests with the specified one first
-r: random -- randomize test execution order
-f: fromfile -- read names of tests to run from a file (see below)
-l: findleaks -- if GC is available detect tests that leak memory
@ -48,6 +49,12 @@ file is missing, the first test_*.py file in testdir or on the command
line is used. (actually tempfile.gettempdir() is used instead of
/tmp).
-S is used to continue running tests after an aborted run. It will
maintain the order a standard run (ie, this assumes -r is not used).
This is useful after the tests have prematurely stopped for some external
reason and you want to start running from where you left off rather
than starting from the beginning.
-f reads the names of tests from the file given as f's argument, one
or more test names per line. Whitespace is ignored. Blank lines and
lines beginning with '#' are ignored. This is especially useful for
@ -177,7 +184,8 @@ def usage(code, msg=''):
def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
exclude=False, single=False, randomize=False, fromfile=None,
findleaks=False, use_resources=None, trace=False, coverdir='coverage',
runleaks=False, huntrleaks=False, verbose2=False, debug=False):
runleaks=False, huntrleaks=False, verbose2=False, debug=False,
start=None):
"""Execute a test suite.
This also parses command-line options and modifies its behavior
@ -202,13 +210,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
test_support.record_original_stdout(sys.stdout)
try:
opts, args = getopt.getopt(sys.argv[1:], 'dhvgqxsrf:lu:t:TD:NLR:wM:',
opts, args = getopt.getopt(sys.argv[1:], 'dhvgqxsS:rf:lu:t:TD:NLR:wM:',
['help', 'verbose', 'quiet', 'generate',
'exclude', 'single', 'random', 'fromfile',
'findleaks', 'use=', 'threshold=', 'trace',
'coverdir=', 'nocoverdir', 'runleaks',
'huntrleaks=', 'verbose2', 'memlimit=',
'debug',
'debug', 'start='
])
except getopt.error as msg:
usage(2, msg)
@ -232,6 +240,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
generate = True
elif o in ('-x', '--exclude'):
exclude = True
elif o in ('-S', '--start'):
start = a
elif o in ('-s', '--single'):
single = True
elif o in ('-r', '--randomize'):
@ -345,6 +355,12 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
tests = tests or args or findtests(testdir, stdtests, nottests)
if single:
tests = tests[:1]
# Remove all the tests that precede start if it's set.
if start:
try:
del tests[:tests.index(start)]
except ValueError:
print("Couldn't find starting test (%s), using all tests" % start)
if randomize:
random.shuffle(tests)
if trace: