mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
-f/--failfast command line option for unittest. Issue 8074. Documentation still needed. Plus minor change to test_unittest to allow it to be run with python -m test.unittest
This commit is contained in:
parent
b1aa30f94d
commit
1b9e95339d
4 changed files with 86 additions and 26 deletions
|
@ -16,6 +16,7 @@ Options:
|
|||
-h, --help Show this message
|
||||
-v, --verbose Verbose output
|
||||
-q, --quiet Minimal output
|
||||
-f, --failfast Stop on first failure
|
||||
|
||||
Examples:
|
||||
%(progName)s test_module - run tests from test_module
|
||||
|
@ -30,6 +31,7 @@ Alternative Usage: %(progName)s discover [options]
|
|||
|
||||
Options:
|
||||
-v, --verbose Verbose output
|
||||
-f, --failfast Stop on first failure
|
||||
-s directory Directory to start discovery ('.' default)
|
||||
-p pattern Pattern to match test files ('test*.py' default)
|
||||
-t directory Top level directory of project (default to
|
||||
|
@ -46,6 +48,7 @@ Options:
|
|||
-h, --help Show this message
|
||||
-v, --verbose Verbose output
|
||||
-q, --quiet Minimal output
|
||||
-f, --failfast Stop on first failure
|
||||
|
||||
Examples:
|
||||
%(progName)s - run default set of tests
|
||||
|
@ -69,7 +72,7 @@ class TestProgram(object):
|
|||
def __init__(self, module='__main__', defaultTest=None,
|
||||
argv=None, testRunner=None,
|
||||
testLoader=loader.defaultTestLoader, exit=True,
|
||||
verbosity=1):
|
||||
verbosity=1, failfast=False):
|
||||
if isinstance(module, basestring):
|
||||
self.module = __import__(module)
|
||||
for part in module.split('.')[1:]:
|
||||
|
@ -80,6 +83,7 @@ class TestProgram(object):
|
|||
argv = sys.argv
|
||||
|
||||
self.exit = exit
|
||||
self.failfast = failfast
|
||||
self.verbosity = verbosity
|
||||
self.defaultTest = defaultTest
|
||||
self.testRunner = testRunner
|
||||
|
@ -100,9 +104,9 @@ class TestProgram(object):
|
|||
return
|
||||
|
||||
import getopt
|
||||
long_opts = ['help','verbose','quiet']
|
||||
long_opts = ['help', 'verbose', 'quiet', 'failfast']
|
||||
try:
|
||||
options, args = getopt.getopt(argv[1:], 'hHvq', long_opts)
|
||||
options, args = getopt.getopt(argv[1:], 'hHvqf', long_opts)
|
||||
for opt, value in options:
|
||||
if opt in ('-h','-H','--help'):
|
||||
self.usageExit()
|
||||
|
@ -110,6 +114,8 @@ class TestProgram(object):
|
|||
self.verbosity = 0
|
||||
if opt in ('-v','--verbose'):
|
||||
self.verbosity = 2
|
||||
if opt in ('-f','--failfast'):
|
||||
self.failfast = True
|
||||
if len(args) == 0 and self.defaultTest is None:
|
||||
# createTests will load tests from self.module
|
||||
self.testNames = None
|
||||
|
@ -137,6 +143,8 @@ class TestProgram(object):
|
|||
parser = optparse.OptionParser()
|
||||
parser.add_option('-v', '--verbose', dest='verbose', default=False,
|
||||
help='Verbose output', action='store_true')
|
||||
parser.add_option('-f', '--failfast', dest='failfast', default=False,
|
||||
help='Stop on first fail or error', action='store_true')
|
||||
parser.add_option('-s', '--start-directory', dest='start', default='.',
|
||||
help="Directory to start discovery ('.' default)")
|
||||
parser.add_option('-p', '--pattern', dest='pattern', default='test*.py',
|
||||
|
@ -153,6 +161,8 @@ class TestProgram(object):
|
|||
|
||||
if options.verbose:
|
||||
self.verbosity = 2
|
||||
if options.failfast:
|
||||
self.failfast = True
|
||||
|
||||
start_dir = options.start
|
||||
pattern = options.pattern
|
||||
|
@ -166,9 +176,10 @@ class TestProgram(object):
|
|||
self.testRunner = runner.TextTestRunner
|
||||
if isinstance(self.testRunner, (type, types.ClassType)):
|
||||
try:
|
||||
testRunner = self.testRunner(verbosity=self.verbosity)
|
||||
testRunner = self.testRunner(verbosity=self.verbosity,
|
||||
failfast=self.failfast)
|
||||
except TypeError:
|
||||
# didn't accept the verbosity argument
|
||||
# didn't accept the verbosity or failfast argument
|
||||
testRunner = self.testRunner()
|
||||
else:
|
||||
# it is assumed to be a TestRunner instance
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue