mirror of https://github.com/python/cpython
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
c1d7c5b7fa
commit
db919f0188
|
@ -133,7 +133,7 @@ class TestSuite(BaseTestSuite):
|
|||
except Exception as e:
|
||||
currentClass._classSetupFailed = True
|
||||
className = util.strclass(currentClass)
|
||||
errorName = 'classSetUp (%s)' % className
|
||||
errorName = 'setUpClass (%s)' % className
|
||||
self._addClassOrModuleLevelException(result, e, errorName)
|
||||
|
||||
|
||||
|
@ -213,7 +213,7 @@ class TestSuite(BaseTestSuite):
|
|||
tearDownClass()
|
||||
except Exception, e:
|
||||
className = util.strclass(previousClass)
|
||||
errorName = 'classTearDown (%s)' % className
|
||||
errorName = 'tearDownClass (%s)' % className
|
||||
self._addClassOrModuleLevelException(result, e, errorName)
|
||||
|
||||
|
||||
|
|
|
@ -639,6 +639,10 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
|
|||
message = self._truncateMessage('foo', 'bar')
|
||||
self.assertEqual(message, 'foobar')
|
||||
|
||||
self.maxDiff = 4
|
||||
message = self._truncateMessage('foo', 'bar')
|
||||
self.assertEqual(message, 'foobar')
|
||||
|
||||
def testAssertDictEqualTruncates(self):
|
||||
test = unittest.TestCase('assertEqual')
|
||||
def truncate(msg, diff):
|
||||
|
|
|
@ -112,7 +112,7 @@ class TestSetups(unittest.TestCase):
|
|||
self.assertEqual(len(result.errors), 1)
|
||||
error, _ = result.errors[0]
|
||||
self.assertEqual(str(error),
|
||||
'classSetUp (%s.BrokenTest)' % __name__)
|
||||
'setUpClass (%s.BrokenTest)' % __name__)
|
||||
|
||||
def test_error_in_teardown_class(self):
|
||||
class Test(unittest.TestCase):
|
||||
|
@ -145,7 +145,7 @@ class TestSetups(unittest.TestCase):
|
|||
|
||||
error, _ = result.errors[0]
|
||||
self.assertEqual(str(error),
|
||||
'classTearDown (%s.Test)' % __name__)
|
||||
'tearDownClass (%s.Test)' % __name__)
|
||||
|
||||
def test_class_not_torndown_when_setup_fails(self):
|
||||
class Test(unittest.TestCase):
|
||||
|
@ -400,6 +400,45 @@ class TestSetups(unittest.TestCase):
|
|||
error, _ = result.errors[0]
|
||||
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