run-tests: record warnings by raising WarnTest
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Apr 2014 14:32:03 -0700
changeset 21444 2b7d364690d8
parent 21443 a6845a042d46
child 21445 092b16448994
run-tests: record warnings by raising WarnTest We continue the conversion of recording test results by raising exceptions.
tests/run-tests.py
--- a/tests/run-tests.py	Sun Apr 20 14:28:29 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 14:32:03 2014 -0700
@@ -604,6 +604,10 @@
 
                 return '.', self.name, ''
 
+        if self._unittest:
+            if warned:
+                raise WarnTest(msg)
+
         return warned and '~' or '!', self.name, msg
 
     def skip(self, msg):
@@ -991,6 +995,9 @@
 class IgnoreTest(Exception):
     """Raised to indicate that a test is to be ignored."""
 
+class WarnTest(Exception):
+    """Raised to indicate that a test warned."""
+
 class TestResult(unittest._TextTestResult):
     """Holds results when executing via unittest."""
     # Don't worry too much about accessing the non-public _TextTestResult.
@@ -1350,6 +1357,8 @@
                     result.addSkip(self, str(e))
                 except IgnoreTest, e:
                     result.addIgnore(self, str(e))
+                except WarnTest, e:
+                    result.addWarn(self, str(e))
                 except self.failureException:
                     result.addFailure(self, sys.exc_info())
                 except Exception:
@@ -1362,10 +1371,8 @@
 
                 if code == '!':
                     self._result.failures.append((self, msg))
-                elif code == '~':
-                    self._result.addWarn(self, msg)
                 # Codes handled in run().
-                elif code in ('.', 's', 'i'):
+                elif code in ('.', 's', 'i', '~'):
                     pass
                 else:
                     self.fail('Unknown test result code: %s' % code)