mirror of https://github.com/python/cpython
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. ........
This commit is contained in:
parent
da562f65e9
commit
520ed0a150
|
@ -127,9 +127,11 @@ 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 = 'setUpClass (%s)' % className
|
||||||
|
self._addClassOrModuleLevelException(result, e, errorName)
|
||||||
|
|
||||||
def _get_previous_module(self, result):
|
def _get_previous_module(self, result):
|
||||||
previousModule = None
|
previousModule = None
|
||||||
|
@ -157,10 +159,18 @@ class TestSuite(BaseTestSuite):
|
||||||
if setUpModule is not None:
|
if setUpModule is not None:
|
||||||
try:
|
try:
|
||||||
setUpModule()
|
setUpModule()
|
||||||
except:
|
except Exception as 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)
|
||||||
|
@ -178,9 +188,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)
|
||||||
|
@ -198,18 +208,11 @@ class TestSuite(BaseTestSuite):
|
||||||
if tearDownClass is not None:
|
if tearDownClass is not None:
|
||||||
try:
|
try:
|
||||||
tearDownClass()
|
tearDownClass()
|
||||||
except:
|
except Exception as e:
|
||||||
self._addClassTearDownError(result)
|
className = util.strclass(previousClass)
|
||||||
|
errorName = 'tearDownClass (%s)' % className
|
||||||
|
self._addClassOrModuleLevelException(result, e, errorName)
|
||||||
|
|
||||||
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())
|
|
||||||
|
|
||||||
|
|
||||||
class _ErrorHolder(object):
|
class _ErrorHolder(object):
|
||||||
|
|
|
@ -641,6 +641,10 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
|
||||||
message = self._truncateMessage('foo', 'bar')
|
message = self._truncateMessage('foo', 'bar')
|
||||||
self.assertEqual(message, 'foobar')
|
self.assertEqual(message, 'foobar')
|
||||||
|
|
||||||
|
self.maxDiff = 4
|
||||||
|
message = self._truncateMessage('foo', 'bar')
|
||||||
|
self.assertEqual(message, 'foobar')
|
||||||
|
|
||||||
def testAssertDictEqualTruncates(self):
|
def testAssertDictEqualTruncates(self):
|
||||||
test = unittest.TestCase('assertEqual')
|
test = unittest.TestCase('assertEqual')
|
||||||
def truncate(msg, diff):
|
def truncate(msg, diff):
|
||||||
|
|
|
@ -111,7 +111,7 @@ class TestSetups(unittest.TestCase):
|
||||||
self.assertEqual(len(result.errors), 1)
|
self.assertEqual(len(result.errors), 1)
|
||||||
error, _ = result.errors[0]
|
error, _ = result.errors[0]
|
||||||
self.assertEqual(str(error),
|
self.assertEqual(str(error),
|
||||||
'classSetUp (%s.BrokenTest)' % __name__)
|
'setUpClass (%s.BrokenTest)' % __name__)
|
||||||
|
|
||||||
def test_error_in_teardown_class(self):
|
def test_error_in_teardown_class(self):
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -144,7 +144,7 @@ class TestSetups(unittest.TestCase):
|
||||||
|
|
||||||
error, _ = result.errors[0]
|
error, _ = result.errors[0]
|
||||||
self.assertEqual(str(error),
|
self.assertEqual(str(error),
|
||||||
'classTearDown (%s.Test)' % __name__)
|
'tearDownClass (%s.Test)' % __name__)
|
||||||
|
|
||||||
def test_class_not_torndown_when_setup_fails(self):
|
def test_class_not_torndown_when_setup_fails(self):
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@ -398,3 +398,46 @@ class TestSetups(unittest.TestCase):
|
||||||
self.assertEqual(len(result.errors), 1)
|
self.assertEqual(len(result.errors), 1)
|
||||||
error, _ = result.errors[0]
|
error, _ = result.errors[0]
|
||||||
self.assertEqual(str(error), 'tearDownModule (Module)')
|
self.assertEqual(str(error), 'tearDownModule (Module)')
|
||||||
|
|
||||||
|
def test_skiptest_in_setupclass(self):
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
raise unittest.SkipTest('foo')
|
||||||
|
def test_one(self):
|
||||||
|
pass
|
||||||
|
def test_two(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
result = self.runTests(Test)
|
||||||
|
self.assertEqual(result.testsRun, 0)
|
||||||
|
self.assertEqual(len(result.errors), 0)
|
||||||
|
self.assertEqual(len(result.skipped), 1)
|
||||||
|
skipped = result.skipped[0][0]
|
||||||
|
self.assertEqual(str(skipped), 'setUpClass (%s.Test)' % __name__)
|
||||||
|
|
||||||
|
def test_skiptest_in_setupmodule(self):
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
def test_one(self):
|
||||||
|
pass
|
||||||
|
def test_two(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Module(object):
|
||||||
|
@staticmethod
|
||||||
|
def setUpModule():
|
||||||
|
raise unittest.SkipTest('foo')
|
||||||
|
|
||||||
|
Test.__module__ = 'Module'
|
||||||
|
sys.modules['Module'] = Module
|
||||||
|
|
||||||
|
result = self.runTests(Test)
|
||||||
|
self.assertEqual(result.testsRun, 0)
|
||||||
|
self.assertEqual(len(result.errors), 0)
|
||||||
|
self.assertEqual(len(result.skipped), 1)
|
||||||
|
skipped = result.skipped[0][0]
|
||||||
|
self.assertEqual(str(skipped), 'setUpModule (Module)')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue