Mercurial > hg
comparison tests/run-tests.py @ 21445:092b16448994
run-tests: fail tests by raising an exception
When in unittest mode, Test.run() will now raise for all non-success
cases. This makes it behave like TestCase.run().
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 14:34:03 -0700 |
parents | 2b7d364690d8 |
children | 9a3b4f795f62 |
comparison
equal
deleted
inserted
replaced
21444:2b7d364690d8 | 21445:092b16448994 |
---|---|
605 return '.', self.name, '' | 605 return '.', self.name, '' |
606 | 606 |
607 if self._unittest: | 607 if self._unittest: |
608 if warned: | 608 if warned: |
609 raise WarnTest(msg) | 609 raise WarnTest(msg) |
610 else: | |
611 # unittest differentiates between errored and failed. | |
612 # Failed is denoted by AssertionError (by default at least). | |
613 raise AssertionError(msg) | |
610 | 614 |
611 return warned and '~' or '!', self.name, msg | 615 return warned and '~' or '!', self.name, msg |
612 | 616 |
613 def skip(self, msg): | 617 def skip(self, msg): |
614 if self._unittest: | 618 if self._unittest: |
1345 return self.name | 1349 return self.name |
1346 | 1350 |
1347 # Need to stash away the TestResult since we do custom things | 1351 # Need to stash away the TestResult since we do custom things |
1348 # with it. | 1352 # with it. |
1349 def run(self, result): | 1353 def run(self, result): |
1350 self._result = result | |
1351 | |
1352 try: | 1354 try: |
1353 self.runTest() | 1355 self.runTest() |
1354 except KeyboardInterrupt: | 1356 except KeyboardInterrupt: |
1355 raise | 1357 raise |
1356 except SkipTest, e: | 1358 except SkipTest, e: |
1367 result.addSuccess(self) | 1369 result.addSuccess(self) |
1368 | 1370 |
1369 def runTest(self): | 1371 def runTest(self): |
1370 code, tname, msg = t.run() | 1372 code, tname, msg = t.run() |
1371 | 1373 |
1372 if code == '!': | 1374 # All non-success conditions should be exceptions and should |
1373 self._result.failures.append((self, msg)) | 1375 # be caught in run(). |
1374 # Codes handled in run(). | 1376 assert code == '.' |
1375 elif code in ('.', 's', 'i', '~'): | |
1376 pass | |
1377 else: | |
1378 self.fail('Unknown test result code: %s' % code) | |
1379 | 1377 |
1380 # We need this proxy until tearDown() is implemented. | 1378 # We need this proxy until tearDown() is implemented. |
1381 def cleanup(self): | 1379 def cleanup(self): |
1382 return t.cleanup() | 1380 return t.cleanup() |
1383 | 1381 |