tests/run-tests.py
changeset 21442 867a1116be3c
parent 21441 213339e9bada
child 21443 a6845a042d46
equal deleted inserted replaced
21441:213339e9bada 21442:867a1116be3c
   605                 return '.', self.name, ''
   605                 return '.', self.name, ''
   606 
   606 
   607         return warned and '~' or '!', self.name, msg
   607         return warned and '~' or '!', self.name, msg
   608 
   608 
   609     def skip(self, msg):
   609     def skip(self, msg):
       
   610         if self._unittest:
       
   611             raise SkipTest(msg)
       
   612 
   610         if self._options.verbose:
   613         if self._options.verbose:
   611             log("\nSkipping %s: %s" % (self._path, msg))
   614             log("\nSkipping %s: %s" % (self._path, msg))
   612 
   615 
   613         return 's', self.name, msg
   616         return 's', self.name, msg
   614 
   617 
   977         output = re.sub(s, r, output)
   980         output = re.sub(s, r, output)
   978     return ret, output.splitlines(True)
   981     return ret, output.splitlines(True)
   979 
   982 
   980 iolock = threading.Lock()
   983 iolock = threading.Lock()
   981 
   984 
       
   985 class SkipTest(Exception):
       
   986     """Raised to indicate that a test is to be skipped."""
       
   987 
   982 class TestResult(unittest._TextTestResult):
   988 class TestResult(unittest._TextTestResult):
   983     """Holds results when executing via unittest."""
   989     """Holds results when executing via unittest."""
   984     # Don't worry too much about accessing the non-public _TextTestResult.
   990     # Don't worry too much about accessing the non-public _TextTestResult.
   985     # It is relatively common in Python testing tools.
   991     # It is relatively common in Python testing tools.
   986     def __init__(self, *args, **kwargs):
   992     def __init__(self, *args, **kwargs):
  1332 
  1338 
  1333                 try:
  1339                 try:
  1334                     self.runTest()
  1340                     self.runTest()
  1335                 except KeyboardInterrupt:
  1341                 except KeyboardInterrupt:
  1336                     raise
  1342                     raise
       
  1343                 except SkipTest, e:
       
  1344                     result.addSkip(self, str(e))
  1337                 except self.failureException:
  1345                 except self.failureException:
  1338                     result.addFailure(self, sys.exc_info())
  1346                     result.addFailure(self, sys.exc_info())
  1339                 except Exception:
  1347                 except Exception:
  1340                     result.addError(self, sys.exc_info())
  1348                     result.addError(self, sys.exc_info())
  1341                 else:
  1349                 else:
  1346 
  1354 
  1347                 if code == '!':
  1355                 if code == '!':
  1348                     self._result.failures.append((self, msg))
  1356                     self._result.failures.append((self, msg))
  1349                 elif code == '~':
  1357                 elif code == '~':
  1350                     self._result.addWarn(self, msg)
  1358                     self._result.addWarn(self, msg)
  1351                 elif code == '.':
       
  1352                     # Success is handled automatically by the built-in run().
       
  1353                     pass
       
  1354                 elif code == 's':
       
  1355                     self._result.addSkip(self, msg)
       
  1356                 elif code == 'i':
  1359                 elif code == 'i':
  1357                     self._result.addIgnore(self, msg)
  1360                     self._result.addIgnore(self, msg)
       
  1361                 # Codes handled in run().
       
  1362                 elif code in ('.', 's'):
       
  1363                     pass
  1358                 else:
  1364                 else:
  1359                     self.fail('Unknown test result code: %s' % code)
  1365                     self.fail('Unknown test result code: %s' % code)
  1360 
  1366 
  1361             # We need this proxy until tearDown() is implemented.
  1367             # We need this proxy until tearDown() is implemented.
  1362             def cleanup(self):
  1368             def cleanup(self):