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.
--- a/tests/run-tests.py Sun Apr 20 16:39:05 2014 -0700
+++ b/tests/run-tests.py Sun Apr 20 16:53:49 2014 -0700
@@ -1046,9 +1046,11 @@
"""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 @@
# 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 @@
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 @@
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 @@
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