diff --git a/tests/run-tests.py b/tests/run-tests.py index 5adc9c7f53..d3d97ae86a 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -377,6 +377,9 @@ class Test(object): 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 @@ class Test(object): 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') @@ -1351,6 +1357,15 @@ class TestRunner(object): # Need to stash away the TestResult since we do custom things # 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: @@ -1366,6 +1381,17 @@ class TestRunner(object): 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):