# HG changeset patch # User Gregory Szorc # Date 2014-04-20 23:53:49 # Node ID df580990507e73b351922609c040256b954fc352 # Parent d5945324b13015c8654fe500565ef3389c84bcaa run-tests: abort tests after first failure in unittest mode There is an execution mode on run-tests.py that stops after the first failure. unittest mode was previously not obeying this option. This patch fixes that. diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1046,9 +1046,11 @@ class TestResult(unittest._TextTestResul """Holds results when executing via unittest.""" # Don't worry too much about accessing the non-public _TextTestResult. # It is relatively common in Python testing tools. - def __init__(self, *args, **kwargs): + def __init__(self, options, *args, **kwargs): super(TestResult, self).__init__(*args, **kwargs) + self._options = options + # unittest.TestResult didn't have skipped until 2.7. We need to # polyfill it. self.skipped = [] @@ -1063,6 +1065,18 @@ class TestResult(unittest._TextTestResul # sense to map it into fail some day. self.warned = [] + def addFailure(self, *args, **kwargs): + super(TestResult, self).addFailure(*args, **kwargs) + + if self._options.first: + self.stop() + + def addError(self, *args, **kwargs): + super(TestResult, self).addError(*args, **kwargs) + + if self._options.first: + self.stop() + # Polyfill. def addSkip(self, test, reason): self.skipped.append((test, reason)) @@ -1085,6 +1099,9 @@ class TestResult(unittest._TextTestResul def addWarn(self, test, reason): self.warned.append((test, reason)) + if self._options.first: + self.stop() + if self.showAll: self.stream.writeln('warned %s' % reason) else: @@ -1113,7 +1130,8 @@ class TextTestRunner(unittest.TextTestRu self._runner = runner def run(self, test): - result = TestResult(self.stream, self.descriptions, self.verbosity) + result = TestResult(self._runner.options, self.stream, + self.descriptions, self.verbosity) test(result) @@ -1706,6 +1724,8 @@ class TestRunner(object): self.results[code].append((test, msg)) if self.options.first and code not in '.si': break + if result and result.shouldStop: + break except queue.Empty: continue running -= 1