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/result.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/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) |
