From 9c164af6c35cc0a0b21162d74bd7ea572731ed2c Mon Sep 17 00:00:00 2001 From: Michael Foord Date: Sat, 8 May 2010 17:06:25 +0000 Subject: unittest: issue 8301. Adding functions to test suites no longer crashes. --- Lib/unittest/suite.py | 7 ++++++- Lib/unittest/test/test_suite.py | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Lib/unittest/suite.py b/Lib/unittest/suite.py index 0dd2dc5..cf6d94a 100644 --- a/Lib/unittest/suite.py +++ b/Lib/unittest/suite.py @@ -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: diff --git a/Lib/unittest/test/test_suite.py b/Lib/unittest/test/test_suite.py index 7cd2b89..2b8d678 100644 --- a/Lib/unittest/test/test_suite.py +++ b/Lib/unittest/test/test_suite.py @@ -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() -- cgit v0.12