Added a -l/--leakdebug option which turns on DEBUG_LEAK if the gc

module is importable.
This commit is contained in:
Barry Warsaw 2000-08-03 15:50:37 +00:00
parent e027d8dc81
commit a873b03ebb

View file

@ -8,12 +8,13 @@ additional facilities.
Command line options: Command line options:
-v: verbose -- run tests in verbose mode with output to stdout -v: verbose -- run tests in verbose mode with output to stdout
-q: quiet -- don't print anything except if a test fails -q: quiet -- don't print anything except if a test fails
-g: generate -- write the output file for a test instead of comparing it -g: generate -- write the output file for a test instead of comparing it
-x: exclude -- arguments are tests to *exclude* -x: exclude -- arguments are tests to *exclude*
-s: single -- run only a single test (see below) -s: single -- run only a single test (see below)
-r: random -- randomize test execution order -r: random -- randomize test execution order
-l: leakdebug -- if cycle garbage collection is enabled, run with DEBUG_LEAK
If non-option arguments are present, they are names for tests to run, 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. unless -x is given, in which case they are names for tests not to run.
@ -39,7 +40,7 @@ import random
import test_support import test_support
def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
exclude=0, single=0, randomize=0): exclude=0, single=0, randomize=0, leakdebug=0):
"""Execute a test suite. """Execute a test suite.
This also parses command-line options and modifies its behavior This also parses command-line options and modifies its behavior
@ -56,14 +57,15 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
command-line will be used. If that's empty, too, then all *.py command-line will be used. If that's empty, too, then all *.py
files beginning with test_ will be used. files beginning with test_ will be used.
The other six default arguments (verbose, quiet, generate, exclude, The other seven default arguments (verbose, quiet, generate, exclude,
single, and randomize) allow programmers calling main() directly to single, randomize, and leakdebug) allow programmers calling main()
set the values that would normally be set by flags on the command directly to set the values that would normally be set by flags on the
line. command line.
""" """
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'vgqxsr') opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl')
except getopt.error, msg: except getopt.error, msg:
print msg print msg
print __doc__ print __doc__
@ -75,6 +77,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
if o == '-x': exclude = 1 if o == '-x': exclude = 1
if o == '-s': single = 1 if o == '-s': single = 1
if o == '-r': randomize = 1 if o == '-r': randomize = 1
if o == '-l': leakdebug = 1
if generate and verbose: if generate and verbose:
print "-g and -v don't go together!" print "-g and -v don't go together!"
return 2 return 2
@ -82,6 +85,14 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
bad = [] bad = []
skipped = [] skipped = []
if leakdebug:
try:
import gc
except ImportError:
print 'cycle garbage collection not available'
else:
gc.set_debug(gc.DEBUG_LEAK)
if single: if single:
from tempfile import gettempdir from tempfile import gettempdir
filename = os.path.join(gettempdir(), 'pynexttest') filename = os.path.join(gettempdir(), 'pynexttest')