diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py index b4b2194a09cf9f..02c59fc21592b8 100644 --- a/Lib/test/test_unittest/test_case.py +++ b/Lib/test/test_unittest/test_case.py @@ -637,6 +637,27 @@ def run(self, result): self.assertIs(retval, resultOut) + # This test verifies that cooperative multiple inheritance works correctly + # when unittest.TestCase is combined with another class. + def test_init_support_cooperative_multiple_inheritance(self): + class Base: + def __init__(self): + super().__init__() + self.base_initialized = True + + class Foo(unittest.TestCase, Base): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.testcase_initialized = True + + def test_inheritance(self): + self.assertTrue(self.base_initialized) + self.assertTrue(self.testcase_initialized) + + result = Foo('test_inheritance').run() + self.assertTrue(result.wasSuccessful()) + + def testShortDescriptionWithoutDocstring(self): self.assertIsNone(self.shortDescription()) diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 55c79d353539ca..7ae56c0ba9aa0f 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -413,6 +413,9 @@ def __init__(self, methodName='runTest'): method when executed. Raises a ValueError if the instance does not have a method with the specified name. """ + + super(TestCase, self).__init__() + self._testMethodName = methodName self._outcome = None self._testMethodDoc = 'No test' diff --git a/Misc/NEWS.d/next/Library/2024-10-11-01-48-04.gh-issue-125252.2hX3Pb.rst b/Misc/NEWS.d/next/Library/2024-10-11-01-48-04.gh-issue-125252.2hX3Pb.rst new file mode 100644 index 00000000000000..b5c51e8600ac3b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-11-01-48-04.gh-issue-125252.2hX3Pb.rst @@ -0,0 +1,2 @@ +Added support :class:`unittest.TestCase` of multiple-inheritance +cooperative.