Re: [Pyunit-interest] __init__() breaks TestCase subclass
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2000-11-20 11:49:31
|
Ng Pheng Siong wrote: > > My test case subclass has an __init__(). If I remove it then all is fine. > > class aClassTestCase(unittest.TestCase): > def __init__(self): > unittest.TestCase.__init__(self) > self.x = 'x' Hi; the problem is that the __init__ method in TestCase takes a parameter that is the name of the test method that will be run by the instance. Therefore, if you override the constructor in subclasses of TestCase, you should always call the base class constructor with an argument. I'm pretty sure this is mentioned in the documentation, but I'll make sure. So, your code should look like this:- class aClassTestCase(unittest.TestCase): def __init__(self, name='check_something'): unittest.TestCase.__init__(self, name) self.x = 'x' Hope that helps. Best wishes, -Steve -- Steve Purcell, Pythangelist "Life must be simple if *I* can do it" -- me |