Commit 20e287ca authored by Michael Foord's avatar Michael Foord

Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as...

Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as a skip rather than an error.
parent ab2eb0ee
...@@ -130,9 +130,12 @@ class TestSuite(BaseTestSuite): ...@@ -130,9 +130,12 @@ class TestSuite(BaseTestSuite):
if setUpClass is not None: if setUpClass is not None:
try: try:
setUpClass() setUpClass()
except: except Exception as e:
currentClass._classSetupFailed = True 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): def _get_previous_module(self, result):
previousModule = None previousModule = None
...@@ -150,7 +153,6 @@ class TestSuite(BaseTestSuite): ...@@ -150,7 +153,6 @@ class TestSuite(BaseTestSuite):
self._handleModuleTearDown(result) self._handleModuleTearDown(result)
result._moduleSetUpFailed = False result._moduleSetUpFailed = False
try: try:
module = sys.modules[currentModule] module = sys.modules[currentModule]
...@@ -160,10 +162,18 @@ class TestSuite(BaseTestSuite): ...@@ -160,10 +162,18 @@ class TestSuite(BaseTestSuite):
if setUpModule is not None: if setUpModule is not None:
try: try:
setUpModule() setUpModule()
except: except Exception, e:
result._moduleSetUpFailed = True result._moduleSetUpFailed = True
error = _ErrorHolder('setUpModule (%s)' % currentModule) errorName = 'setUpModule (%s)' % currentModule
result.addError(error, sys.exc_info()) 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): def _handleModuleTearDown(self, result):
previousModule = self._get_previous_module(result) previousModule = self._get_previous_module(result)
...@@ -181,9 +191,9 @@ class TestSuite(BaseTestSuite): ...@@ -181,9 +191,9 @@ class TestSuite(BaseTestSuite):
if tearDownModule is not None: if tearDownModule is not None:
try: try:
tearDownModule() tearDownModule()
except: except Exception as e:
error = _ErrorHolder('tearDownModule (%s)' % previousModule) errorName = 'tearDownModule (%s)' % previousModule
result.addError(error, sys.exc_info()) self._addClassOrModuleLevelException(result, e, errorName)
def _tearDownPreviousClass(self, test, result): def _tearDownPreviousClass(self, test, result):
previousClass = getattr(result, '_previousTestClass', None) previousClass = getattr(result, '_previousTestClass', None)
...@@ -201,18 +211,10 @@ class TestSuite(BaseTestSuite): ...@@ -201,18 +211,10 @@ class TestSuite(BaseTestSuite):
if tearDownClass is not None: if tearDownClass is not None:
try: try:
tearDownClass() tearDownClass()
except: except Exception, e:
self._addClassTearDownError(result) className = util.strclass(previousClass)
errorName = 'classTearDown (%s)' % className
def _addClassTearDownError(self, result): self._addClassOrModuleLevelException(result, e, errorName)
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())
class _ErrorHolder(object): class _ErrorHolder(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment