changeset 21460:df580990507e

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Apr 2014 16:53:49 -0700
parents d5945324b130
children a46a91989d57
files tests/run-tests.py
diffstat 1 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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