diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index 72b294962b9..a7238522f61 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -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: diff --git a/Lib/unittest/test/test_suite.py b/Lib/unittest/test/test_suite.py index 465ba75d74d..ab2e16eb99a 100644 --- a/Lib/unittest/test/test_suite.py +++ b/Lib/unittest/test/test_suite.py @@ -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()