Mercurial > hg
comparison tests/run-tests.py @ 21446:9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
unittest.TestCase.run() calls setUp() and tearDown() during run(). We
emulate that implementation.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 20 Apr 2014 14:41:11 -0700 |
parents | 092b16448994 |
children | f8c5b8a288c5 |
comparison
equal
deleted
inserted
replaced
21445:092b16448994 | 21446:9a3b4f795f62 |
---|---|
375 killdaemons(entry) | 375 killdaemons(entry) |
376 | 376 |
377 if self._threadtmp and not self._options.keep_tmpdir: | 377 if self._threadtmp and not self._options.keep_tmpdir: |
378 shutil.rmtree(self._threadtmp, True) | 378 shutil.rmtree(self._threadtmp, True) |
379 | 379 |
380 def setUp(self): | |
381 """Tasks to perform before run().""" | |
382 | |
380 def run(self): | 383 def run(self): |
381 """Run this test instance. | 384 """Run this test instance. |
382 | 385 |
383 This will return a tuple describing the result of the test. | 386 This will return a tuple describing the result of the test. |
384 """ | 387 """ |
503 iolock.release() | 506 iolock.release() |
504 | 507 |
505 self._runner.times.append((self.name, duration)) | 508 self._runner.times.append((self.name, duration)) |
506 | 509 |
507 return res | 510 return res |
511 | |
512 def tearDown(self): | |
513 """Tasks to perform after run().""" | |
508 | 514 |
509 def _run(self, testtmp, replacements, env): | 515 def _run(self, testtmp, replacements, env): |
510 # This should be implemented in child classes to run tests. | 516 # This should be implemented in child classes to run tests. |
511 return self._skip('unknown test type') | 517 return self._skip('unknown test type') |
512 | 518 |
1350 | 1356 |
1351 # Need to stash away the TestResult since we do custom things | 1357 # Need to stash away the TestResult since we do custom things |
1352 # with it. | 1358 # with it. |
1353 def run(self, result): | 1359 def run(self, result): |
1354 try: | 1360 try: |
1361 t.setUp() | |
1362 except (KeyboardInterrupt, SystemExit): | |
1363 raise | |
1364 except Exception: | |
1365 result.addError(self, sys.exc_info()) | |
1366 return | |
1367 | |
1368 success = False | |
1369 try: | |
1355 self.runTest() | 1370 self.runTest() |
1356 except KeyboardInterrupt: | 1371 except KeyboardInterrupt: |
1357 raise | 1372 raise |
1358 except SkipTest, e: | 1373 except SkipTest, e: |
1359 result.addSkip(self, str(e)) | 1374 result.addSkip(self, str(e)) |
1364 except self.failureException: | 1379 except self.failureException: |
1365 result.addFailure(self, sys.exc_info()) | 1380 result.addFailure(self, sys.exc_info()) |
1366 except Exception: | 1381 except Exception: |
1367 result.addError(self, sys.exc_info()) | 1382 result.addError(self, sys.exc_info()) |
1368 else: | 1383 else: |
1384 success = True | |
1385 | |
1386 try: | |
1387 t.tearDown() | |
1388 except (KeyboardInterrupt, SystemExit): | |
1389 raise | |
1390 except Exception: | |
1391 result.addError(self, sys.exc_info()) | |
1392 success = False | |
1393 | |
1394 if success: | |
1369 result.addSuccess(self) | 1395 result.addSuccess(self) |
1370 | 1396 |
1371 def runTest(self): | 1397 def runTest(self): |
1372 code, tname, msg = t.run() | 1398 code, tname, msg = t.run() |
1373 | 1399 |