diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 21:12:23 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-06-05 21:12:23 (GMT) |
commit | 520ed0a1502583acd69155a5345a0db4131bef83 (patch) | |
tree | 45fc64c55a4719a1d741b827c1c0a61f46053771 /Lib/unittest/suite.py | |
parent | da562f65e985b59e292916955aa18b9dd58ba26f (diff) | |
download | cpython-520ed0a1502583acd69155a5345a0db4131bef83.zip cpython-520ed0a1502583acd69155a5345a0db4131bef83.tar.gz cpython-520ed0a1502583acd69155a5345a0db4131bef83.tar.bz2 |
Merged revisions 81764 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81764 | michael.foord | 2010-06-05 21:59:00 +0100 (Sat, 05 Jun 2010) | 1 line
Tests for issue 8302, skipped test in a setUpClass or a setUpModule are reported as skips rather than errors.
........
Diffstat (limited to 'Lib/unittest/suite.py')
-rw-r--r-- | Lib/unittest/suite.py | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index a723852..0072f20 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -127,9 +127,11 @@ 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 = 'setUpClass (%s)' % className + self._addClassOrModuleLevelException(result, e, errorName) def _get_previous_module(self, result): previousModule = None @@ -157,10 +159,18 @@ class TestSuite(BaseTestSuite): if setUpModule is not None: try: setUpModule() - except: + except Exception as 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) @@ -178,9 +188,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) @@ -198,18 +208,11 @@ 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 as e: + className = util.strclass(previousClass) + errorName = 'tearDownClass (%s)' % className + self._addClassOrModuleLevelException(result, e, errorName) + class _ErrorHolder(object): |