]> granicus.if.org Git - python/commitdiff
Merged revisions 80997 via svnmerge from
authorMichael Foord <fuzzyman@voidspace.org.uk>
Sat, 8 May 2010 17:10:05 +0000 (17:10 +0000)
committerMichael Foord <fuzzyman@voidspace.org.uk>
Sat, 8 May 2010 17:10:05 +0000 (17:10 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80997 | michael.foord | 2010-05-08 19:06:25 +0200 (Sat, 08 May 2010) | 1 line

  unittest: issue 8301. Adding functions to test suites no longer crashes.
........

Lib/unittest/suite.py
Lib/unittest/test/test_suite.py

index 72b294962b9ac2d19f4638d0a69d1c7c587acd3f..a7238522f61102502bde4cbf19e151aa0192fb7a 100644 (file)
@@ -116,7 +116,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 465ba75d74d88a1692ee6a3874b8f37af67e321b..ab2e16eb99a4bb3b82fcfd1fba13b3012f434ebf 100644 (file)
@@ -289,3 +289,16 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
     def test_addTests__string(self):
         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()