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/test | |
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/test')
-rw-r--r-- | Lib/unittest/test/test_case.py | 4 | ||||
-rw-r--r-- | Lib/unittest/test/test_setups.py | 47 |
2 files changed, 49 insertions, 2 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index b7dfa68..00883c9 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -641,6 +641,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): diff --git a/Lib/unittest/test/test_setups.py b/Lib/unittest/test/test_setups.py index 0d1e8bc..3f2994b 100644 --- a/Lib/unittest/test/test_setups.py +++ b/Lib/unittest/test/test_setups.py @@ -111,7 +111,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): @@ -144,7 +144,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): @@ -398,3 +398,46 @@ class TestSetups(unittest.TestCase): self.assertEqual(len(result.errors), 1) 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() |