diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-03-22 01:13:48 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-03-22 01:13:48 (GMT) |
commit | 8769fd8a17dad1b1861c04ea75ce46478d21a34d (patch) | |
tree | d560c681b9e306646f9f54eb3e7c4bba29b0b7ef /Lib/unittest/main.py | |
parent | dccc1fcfafd37c6fd94ca766516cb4903b29668e (diff) | |
download | cpython-8769fd8a17dad1b1861c04ea75ce46478d21a34d.zip cpython-8769fd8a17dad1b1861c04ea75ce46478d21a34d.tar.gz cpython-8769fd8a17dad1b1861c04ea75ce46478d21a34d.tar.bz2 |
Merged revisions 79265-79266 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79265 | michael.foord | 2010-03-21 20:01:34 -0500 (Sun, 21 Mar 2010) | 1 line
-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
........
r79266 | michael.foord | 2010-03-21 20:02:23 -0500 (Sun, 21 Mar 2010) | 1 line
Fix failing test committed by accident.
........
Diffstat (limited to 'Lib/unittest/main.py')
-rw-r--r-- | Lib/unittest/main.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/unittest/main.py b/Lib/unittest/main.py index e04ec16..63fbd16 100644 --- a/Lib/unittest/main.py +++ b/Lib/unittest/main.py @@ -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, str): 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): 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 |