run-tests: record skips by raising SkipTest
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Apr 2014 14:23:50 -0700
changeset 21442 867a1116be3c
parent 21441 213339e9bada
child 21443 a6845a042d46
run-tests: record skips by raising SkipTest The unittest way of recording a skipped test is to raise an exception (at least with modern unittest implementation). We change Test to raise a SkipTest when operating in unittest mode. This does prevent some "tear down" activities from running in unittest mode. This will be fixed in subsequent patches. Since unittest mode is experimental, this should be OK.
tests/run-tests.py
--- a/tests/run-tests.py	Sun Apr 20 14:19:59 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 14:23:50 2014 -0700
@@ -607,6 +607,9 @@
         return warned and '~' or '!', self.name, msg
 
     def skip(self, msg):
+        if self._unittest:
+            raise SkipTest(msg)
+
         if self._options.verbose:
             log("\nSkipping %s: %s" % (self._path, msg))
 
@@ -979,6 +982,9 @@
 
 iolock = threading.Lock()
 
+class SkipTest(Exception):
+    """Raised to indicate that a test is to be skipped."""
+
 class TestResult(unittest._TextTestResult):
     """Holds results when executing via unittest."""
     # Don't worry too much about accessing the non-public _TextTestResult.
@@ -1334,6 +1340,8 @@
                     self.runTest()
                 except KeyboardInterrupt:
                     raise
+                except SkipTest, e:
+                    result.addSkip(self, str(e))
                 except self.failureException:
                     result.addFailure(self, sys.exc_info())
                 except Exception:
@@ -1348,13 +1356,11 @@
                     self._result.failures.append((self, msg))
                 elif code == '~':
                     self._result.addWarn(self, msg)
-                elif code == '.':
-                    # Success is handled automatically by the built-in run().
-                    pass
-                elif code == 's':
-                    self._result.addSkip(self, msg)
                 elif code == 'i':
                     self._result.addIgnore(self, msg)
+                # Codes handled in run().
+                elif code in ('.', 's'):
+                    pass
                 else:
                     self.fail('Unknown test result code: %s' % code)