diff options
| author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-03-22 01:01:34 (GMT) |
|---|---|---|
| committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-03-22 01:01:34 (GMT) |
| commit | 1b9e95339de2f592b48c7640857956e28f2ce859 (patch) | |
| tree | 27243ef2a4b12616522d31fc5f1ab6794fc008c1 /Lib/unittest/result.py | |
| parent | b1aa30f94ded4e9d1094ec890758d913b8725085 (diff) | |
| download | cpython-1b9e95339de2f592b48c7640857956e28f2ce859.zip cpython-1b9e95339de2f592b48c7640857956e28f2ce859.tar.gz cpython-1b9e95339de2f592b48c7640857956e28f2ce859.tar.bz2 | |
-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
Diffstat (limited to 'Lib/unittest/result.py')
| -rw-r--r-- | Lib/unittest/result.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/unittest/result.py b/Lib/unittest/result.py index 91cf218..96d56a1 100644 --- a/Lib/unittest/result.py +++ b/Lib/unittest/result.py @@ -3,9 +3,17 @@ import traceback from . import util +from functools import wraps __unittest = True +def failfast(method): + @wraps(method) + def inner(self, *args, **kw): + if getattr(self, 'failfast', False): + self.stop() + return method(self, *args, **kw) + return inner class TestResult(object): """Holder for test result information. @@ -21,6 +29,7 @@ class TestResult(object): _previousTestClass = None _moduleSetUpFailed = False def __init__(self, stream=None, descriptions=None, verbosity=None): + self.failfast = False self.failures = [] self.errors = [] self.testsRun = 0 @@ -51,12 +60,14 @@ class TestResult(object): See stopTest for a method called after each test. """ + @failfast def addError(self, test, err): """Called when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info(). """ self.errors.append((test, self._exc_info_to_string(err, test))) + @failfast def addFailure(self, test, err): """Called when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().""" @@ -70,11 +81,13 @@ class TestResult(object): """Called when a test is skipped.""" self.skipped.append((test, reason)) + @failfast def addExpectedFailure(self, test, err): """Called when an expected failure/error occured.""" self.expectedFailures.append( (test, self._exc_info_to_string(err, test))) + @failfast def addUnexpectedSuccess(self, test): """Called when a test was expected to fail, but succeed.""" self.unexpectedSuccesses.append(test) |
