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