import unittest class AResult(unittest.TestResult): # this result class does something interesting with stream, # descriptions, and verbosity, so it requires them in its __init__ # and presumably uses them in other methods. def __init__(self, stream, descriptions, verbosity): super(AResult, self).__init__(stream, descriptions, verbosity) self.stream = stream self.descriptions = descriptions self.verbosity = verbosity class ATextResult(unittest.TextTestResult, AResult): # this result class descends--possibly through a more complex # inheritance chain--from both TextTestResult and AResult, adding some # of its own nifty code in the process. in particular, though, its # parent ordering puts TextTestResult earlier in the __mro__ than # AResult # NB: client code can work around this by swapping the parent order of # this class. that's pretty non-obvious, though, so it doesn't seem like # a good final answer to this problem. pass class DummyTestCase(unittest.TestCase): # we need to run a test to demonstrate the problem. this one should pass. def testSanity(self): self.assertEqual(1, 1) if __name__ == '__main__': # TextTestRunner or a descendent does something spiffy in our app but # needs ATextResult result objects to do it. runner = unittest.TextTestRunner(resultclass=ATextResult) # when we run the tests, creating the results object calls # TextTestResult.__init__(...). that method calls super(TextTestResult, # self).__init__() [no args], presumably assuming its parent is # TestResult. unfortunately, it's in ATextResult's __mro__ chain, which # puts AResult *after* TextTestResult. TextTestResult.__init__(...) thus # calls AResult.__init__(), which is invalid. it explodes because of the # incorrect call in TextTestResult.__init__(...), which should pass on # its own args instead of calling its super with no args. unittest.main(testRunner=runner)