diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-10 16:16:08 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-10 16:16:08 (GMT) |
commit | b8748741945beb03ccb6bcf59b08f590109cb21b (patch) | |
tree | 36ceae277408765488c67d107449a5117593c836 /Lib/unittest/suite.py | |
parent | c73013127b2791476ade69d36b69736b9caa674c (diff) | |
download | cpython-b8748741945beb03ccb6bcf59b08f590109cb21b.zip cpython-b8748741945beb03ccb6bcf59b08f590109cb21b.tar.gz cpython-b8748741945beb03ccb6bcf59b08f590109cb21b.tar.bz2 |
Merged revisions 81853 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81853 | michael.foord | 2010-06-08 23:44:52 +0100 (Tue, 08 Jun 2010) | 1 line
Issue 8948. cleanup functions are not run by unittest.TestCase.debug(), plus class and module teardowns are not run by unittest.TestSuite.debug().
........
Diffstat (limited to 'Lib/unittest/suite.py')
-rw-r--r-- | Lib/unittest/suite.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index 0072f20..a543e81 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -84,9 +84,16 @@ class TestSuite(BaseTestSuite): self._handleModuleTearDown(result) return result + def debug(self): + """Run the tests without collecting errors in a TestResult""" + debug = _DebugResult() + self._wrapped_run(debug, True) + self._tearDownPreviousClass(None, debug) + self._handleModuleTearDown(debug) + ################################ # private methods - def _wrapped_run(self, result): + def _wrapped_run(self, result, debug=False): for test in self: if result.shouldStop: break @@ -103,8 +110,10 @@ class TestSuite(BaseTestSuite): if hasattr(test, '_wrapped_run'): test._wrapped_run(result) - else: + elif not debug: test(result) + else: + test.debug() def _handleClassSetUp(self, test, result): previousClass = getattr(result, '_previousTestClass', None) @@ -128,6 +137,8 @@ class TestSuite(BaseTestSuite): try: setUpClass() except Exception as e: + if isinstance(result, _DebugResult): + raise currentClass._classSetupFailed = True className = util.strclass(currentClass) errorName = 'setUpClass (%s)' % className @@ -160,6 +171,8 @@ class TestSuite(BaseTestSuite): try: setUpModule() except Exception as e: + if isinstance(result, _DebugResult): + raise result._moduleSetUpFailed = True errorName = 'setUpModule (%s)' % currentModule self._addClassOrModuleLevelException(result, e, errorName) @@ -189,6 +202,8 @@ class TestSuite(BaseTestSuite): try: tearDownModule() except Exception as e: + if isinstance(result, _DebugResult): + raise errorName = 'tearDownModule (%s)' % previousModule self._addClassOrModuleLevelException(result, e, errorName) @@ -209,6 +224,8 @@ class TestSuite(BaseTestSuite): try: tearDownClass() except Exception as e: + if isinstance(result, _DebugResult): + raise className = util.strclass(previousClass) errorName = 'tearDownClass (%s)' % className self._addClassOrModuleLevelException(result, e, errorName) @@ -260,3 +277,10 @@ def _isnotsuite(test): except TypeError: return True return False + + +class _DebugResult(object): + "Used by the TestSuite to hold previous class when running in debug." + _previousTestClass = None + _moduleSetUpFailed = False + shouldStop = False |