Commit db919f01 authored by Michael Foord's avatar Michael Foord

Tests for issue 8302, skipped test in a setUpClass or a setUpModule are...

Tests for issue 8302, skipped test in a setUpClass or a setUpModule are reported as skips rather than errors.
parent c1d7c5b7
...@@ -133,7 +133,7 @@ class TestSuite(BaseTestSuite): ...@@ -133,7 +133,7 @@ class TestSuite(BaseTestSuite):
except Exception as e: except Exception as e:
currentClass._classSetupFailed = True currentClass._classSetupFailed = True
className = util.strclass(currentClass) className = util.strclass(currentClass)
errorName = 'classSetUp (%s)' % className errorName = 'setUpClass (%s)' % className
self._addClassOrModuleLevelException(result, e, errorName) self._addClassOrModuleLevelException(result, e, errorName)
...@@ -213,7 +213,7 @@ class TestSuite(BaseTestSuite): ...@@ -213,7 +213,7 @@ class TestSuite(BaseTestSuite):
tearDownClass() tearDownClass()
except Exception, e: except Exception, e:
className = util.strclass(previousClass) className = util.strclass(previousClass)
errorName = 'classTearDown (%s)' % className errorName = 'tearDownClass (%s)' % className
self._addClassOrModuleLevelException(result, e, errorName) self._addClassOrModuleLevelException(result, e, errorName)
......
...@@ -639,6 +639,10 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): ...@@ -639,6 +639,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):
......
...@@ -112,7 +112,7 @@ class TestSetups(unittest.TestCase): ...@@ -112,7 +112,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):
...@@ -145,7 +145,7 @@ class TestSetups(unittest.TestCase): ...@@ -145,7 +145,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):
...@@ -400,6 +400,45 @@ class TestSetups(unittest.TestCase): ...@@ -400,6 +400,45 @@ class TestSetups(unittest.TestCase):
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__': if __name__ == '__main__':
unittest.main() unittest.main()
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