Mercurial > hg-stable
changeset 21442:867a1116be3c
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.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 14:23:50 -0700 |
parents | 213339e9bada |
children | a6845a042d46 |
files | tests/run-tests.py |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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)