]> granicus.if.org Git - python/commitdiff
unittest: issue 8301. Adding functions to test suites no longer crashes.
authorMichael Foord <fuzzyman@voidspace.org.uk>
Sat, 8 May 2010 17:06:25 +0000 (17:06 +0000)
committerMichael Foord <fuzzyman@voidspace.org.uk>
Sat, 8 May 2010 17:06:25 +0000 (17:06 +0000)
Lib/unittest/suite.py
Lib/unittest/test/test_suite.py

index 0dd2dc56f1a4d3da94b8b38a85b2122e2279a07a..cf6d94a4026b54c8b9b2934aa99c69d5c65416ef 100644 (file)
@@ -119,7 +119,12 @@ class TestSuite(BaseTestSuite):
         if getattr(currentClass, "__unittest_skip__", False):
             return
 
-        currentClass._classSetupFailed = False
+        try:
+            currentClass._classSetupFailed = False
+        except TypeError:
+            # test may actually be a function
+            # so its class will be a builtin-type
+            pass
 
         setUpClass = getattr(currentClass, 'setUpClass', None)
         if setUpClass is not None:
index 7cd2b897679c077c632006c4bca123d7c65a64c7..2b8d678ca3654dcb1ad7fa7b478f84b9a5cd8b55 100644 (file)
@@ -290,6 +290,15 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
         suite = unittest.TestSuite()
         self.assertRaises(TypeError, suite.addTests, "foo")
 
+    def test_function_in_suite(self):
+        def f(_):
+            pass
+        suite = unittest.TestSuite()
+        suite.addTest(f)
+
+        # when the bug is fixed this line will not crash
+        suite.run(unittest.TestResult())
+
 
 if __name__ == '__main__':
     unittest.main()