diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2006-08-11 10:58:16 +0200 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2006-08-11 10:58:16 +0200 |
commit | 03c6d8a0da9d52cb51e46bcc2239a6dad7e0744c (patch) | |
tree | f3cb2a4f281d89de4d9bf2d123fc8bd03e11cbbe /testlib.py | |
parent | 6fb543b4225ca8d51a00e5a3a801f4f700f59e57 (diff) | |
download | logilab-common-03c6d8a0da9d52cb51e46bcc2239a6dad7e0744c.tar.gz |
small refactoring. We could probably still refactor TestCase._proceed and TestCase.quiet_run
Diffstat (limited to 'testlib.py')
-rw-r--r-- | testlib.py | 58 |
1 files changed, 16 insertions, 42 deletions
@@ -628,14 +628,6 @@ def capture_stderr(): """ return _capture('stderr') -def quiet_run(function, *args, **kwargs): - output = capture_stdout() - errput = capture_stderr() - try: - result = function(*args, **kwargs) - finally: - return result, output.restore(), errput.restore() - def unittest_main(): """use this functon if you want to have the same functionality @@ -700,19 +692,19 @@ class TestCase(unittest.TestCase): self._captured_stderr += err -## def quiet_run(self, func, *args, **kwargs): -## self._start_capture() -## try: -## func(*args, **kwargs) -## except KeyboardInterrupt: -## self._stop_capture() -## raise -## except: -## self._stop_capture() -## result.addError(self, self.__exc_info()) -## return -## self._stop_capture() - + def quiet_run(self, result, func, *args, **kwargs): + self._start_capture() + try: + func(*args, **kwargs) + except KeyboardInterrupt: + self._stop_capture() + raise + except: + self._stop_capture() + result.addError(self, self.__exc_info()) + return False + self._stop_capture() + return True def __call__(self, result=None): """rewrite TestCase.__call__ to support generative tests @@ -724,17 +716,8 @@ class TestCase(unittest.TestCase): self.capture = getattr(result, 'capture', False) result.startTest(self) testMethod = getattr(self, self.__testMethodName) - self._start_capture() try: - try: - self.setUp() - self._stop_capture() - except KeyboardInterrupt: - self._stop_capture() - raise - except: - self._stop_capture() - result.addError(self, self.__exc_info()) + if not self.quiet_run(result, self.setUp): return # generative tests if is_generator(testMethod.im_func): @@ -742,17 +725,8 @@ class TestCase(unittest.TestCase): else: status = self._proceed(result, testMethod) success = (status == 0) - try: - self._start_capture() - self.tearDown() - self._stop_capture() - except KeyboardInterrupt: - self._stop_capture() - raise - except: - self._stop_capture() - result.addError(self, self.__exc_info()) - success = False + if not self.quiet_run(result, self.tearDown): + return if success: result.addSuccess(self) finally: |