Mercurial > hg-stable
changeset 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 |
files | tests/run-tests.py |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Sun Apr 20 14:34:03 2014 -0700 +++ b/tests/run-tests.py Sun Apr 20 14:41:11 2014 -0700 @@ -377,6 +377,9 @@ if self._threadtmp and not self._options.keep_tmpdir: shutil.rmtree(self._threadtmp, True) + def setUp(self): + """Tasks to perform before run().""" + def run(self): """Run this test instance. @@ -506,6 +509,9 @@ return res + def tearDown(self): + """Tasks to perform after run().""" + def _run(self, testtmp, replacements, env): # This should be implemented in child classes to run tests. return self._skip('unknown test type') @@ -1352,6 +1358,15 @@ # with it. def run(self, result): try: + t.setUp() + except (KeyboardInterrupt, SystemExit): + raise + except Exception: + result.addError(self, sys.exc_info()) + return + + success = False + try: self.runTest() except KeyboardInterrupt: raise @@ -1366,6 +1381,17 @@ except Exception: result.addError(self, sys.exc_info()) else: + success = True + + try: + t.tearDown() + except (KeyboardInterrupt, SystemExit): + raise + except Exception: + result.addError(self, sys.exc_info()) + success = False + + if success: result.addSuccess(self) def runTest(self):