diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 19:38:42 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 19:38:42 (GMT) |
commit | 20e287caed7d2b11c12ed5e229901bc722663913 (patch) | |
tree | fa2ab415e94a30f810eecbce58f2a8e0bba9e065 /Lib/unittest/suite.py | |
parent | ab2eb0ee84ceb4b8f28653559248adb43a9502de (diff) | |
download | cpython-20e287caed7d2b11c12ed5e229901bc722663913.zip cpython-20e287caed7d2b11c12ed5e229901bc722663913.tar.gz cpython-20e287caed7d2b11c12ed5e229901bc722663913.tar.bz2 |
Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as a skip rather than an error.
Diffstat (limited to 'Lib/unittest/suite.py')
-rw-r--r-- | Lib/unittest/suite.py | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index cf6d94a..74d5800 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -130,9 +130,12 @@ class TestSuite(BaseTestSuite): if setUpClass is not None: try: setUpClass() - except: + except Exception as e: currentClass._classSetupFailed = True - self._addClassSetUpError(result, currentClass) + className = util.strclass(currentClass) + errorName = 'classSetUp (%s)' % className + self._addClassOrModuleLevelException(result, e, errorName) + def _get_previous_module(self, result): previousModule = None @@ -150,7 +153,6 @@ class TestSuite(BaseTestSuite): self._handleModuleTearDown(result) - result._moduleSetUpFailed = False try: module = sys.modules[currentModule] @@ -160,10 +162,18 @@ class TestSuite(BaseTestSuite): if setUpModule is not None: try: setUpModule() - except: + except Exception, e: result._moduleSetUpFailed = True - error = _ErrorHolder('setUpModule (%s)' % currentModule) - result.addError(error, sys.exc_info()) + errorName = 'setUpModule (%s)' % currentModule + self._addClassOrModuleLevelException(result, e, errorName) + + def _addClassOrModuleLevelException(self, result, exception, errorName): + error = _ErrorHolder(errorName) + addSkip = getattr(result, 'addSkip', None) + if addSkip is not None and isinstance(exception, case.SkipTest): + addSkip(error, str(exception)) + else: + result.addError(error, sys.exc_info()) def _handleModuleTearDown(self, result): previousModule = self._get_previous_module(result) @@ -181,9 +191,9 @@ class TestSuite(BaseTestSuite): if tearDownModule is not None: try: tearDownModule() - except: - error = _ErrorHolder('tearDownModule (%s)' % previousModule) - result.addError(error, sys.exc_info()) + except Exception as e: + errorName = 'tearDownModule (%s)' % previousModule + self._addClassOrModuleLevelException(result, e, errorName) def _tearDownPreviousClass(self, test, result): previousClass = getattr(result, '_previousTestClass', None) @@ -201,18 +211,10 @@ class TestSuite(BaseTestSuite): if tearDownClass is not None: try: tearDownClass() - except: - self._addClassTearDownError(result) - - def _addClassTearDownError(self, result): - className = util.strclass(result._previousTestClass) - error = _ErrorHolder('classTearDown (%s)' % className) - result.addError(error, sys.exc_info()) - - def _addClassSetUpError(self, result, klass): - className = util.strclass(klass) - error = _ErrorHolder('classSetUp (%s)' % className) - result.addError(error, sys.exc_info()) + except Exception, e: + className = util.strclass(previousClass) + errorName = 'classTearDown (%s)' % className + self._addClassOrModuleLevelException(result, e, errorName) class _ErrorHolder(object): |