diff options
author | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-22 23:28:32 (GMT) |
---|---|---|
committer | Michael Foord <fuzzyman@voidspace.org.uk> | 2010-02-22 23:28:32 (GMT) |
commit | ae3db0a12b0c5ca42ea9fe54161d56c57269ea92 (patch) | |
tree | 5a636558ffc55d6f41efdece75cb2163056b4ce1 /Lib/test | |
parent | 4b81bc7fe6aad900cf2904c8a22a2c70a8b42659 (diff) | |
download | cpython-ae3db0a12b0c5ca42ea9fe54161d56c57269ea92.zip cpython-ae3db0a12b0c5ca42ea9fe54161d56c57269ea92.tar.gz cpython-ae3db0a12b0c5ca42ea9fe54161d56c57269ea92.tar.bz2 |
Support for old TestResult object (unittest) with warnings when using unsupported features.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_unittest.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index df760a7..d5f9a5c 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -2062,6 +2062,53 @@ class Test_TestResult(TestCase): 'Tests getDescription() for a method with a longer ' 'docstring.')) +classDict = dict(unittest.TestResult.__dict__) +for m in 'addSkip', 'addExpectedFailure', 'addUnexpectedSuccess': + del classDict[m] +OldResult = type('OldResult', (object,), classDict) + +class Test_OldTestResult(unittest.TestCase): + + def assertOldResultWarning(self, test, failures): + with warnings.catch_warnings(record=True) as log: + result = OldResult() + test.run(result) + self.assertEqual(len(result.failures), failures) + warning, = log + self.assertIs(warning.category, RuntimeWarning) + + def testOldTestResult(self): + class Test(unittest.TestCase): + def testSkip(self): + self.skipTest('foobar') + @unittest.expectedFailure + def testExpectedFail(self): + raise TypeError + @unittest.expectedFailure + def testUnexpectedSuccess(self): + pass + + for test_name, should_pass in (('testSkip', True), + ('testExpectedFail', True), + ('testUnexpectedSuccess', False)): + test = Test(test_name) + self.assertOldResultWarning(test, int(not should_pass)) + + def testOldTestTesultSetup(self): + class Test(unittest.TestCase): + def setUp(self): + self.skipTest('no reason') + def testFoo(self): + pass + self.assertOldResultWarning(Test('testFoo'), 0) + + def testOldTestResultClass(self): + @unittest.skip('no reason') + class Test(unittest.TestCase): + def testFoo(self): + pass + self.assertOldResultWarning(Test('testFoo'), 0) + ### Support code for Test_TestCase ################################################################ @@ -3826,7 +3873,8 @@ def test_main(): test_support.run_unittest(Test_TestCase, Test_TestLoader, Test_TestSuite, Test_TestResult, Test_FunctionTestCase, Test_TestSkipping, Test_Assertions, TestLongMessage, - Test_TestProgram, TestCleanUp, TestDiscovery, Test_TextTestRunner) + Test_TestProgram, TestCleanUp, TestDiscovery, Test_TextTestRunner, + Test_OldTestResult) if __name__ == "__main__": test_main() |