Hi Navin, I can't use setUp as this will be called every time for each test cases, I thought of using setUpClass decorator but there i can define self.
import unittest2 class XMLSupport(unittest2.TestCase): def __init__(self): super(XMLSupport,self).__init__(*args, **kwargs) self.x = 3 def test_3(self): print (self.x) self.x += 1 def test_4(self): print (self.x) I used this way as explained by you, still getting the same error. Thanks Nitin K On Mon, Mar 14, 2011 at 2:24 PM, Navin Kabra <navin.ka...@gmail.com> wrote: > On Mon, Mar 14, 2011 at 1:56 PM, Nitin Kumar <nitin.n...@gmail.com> wrote: > > > See below small example. I am trying to have one constructor for a class > > with unittest inherited. > > Avoid overriding the constructor of TestCase. That is not recommended. > > > > > self.x = 3 > > > Put this is "setUp" instead of the constructor > > *unittest2.TestCase.__init__(self) > > > > If you must do this, the correct way of doing it is: > > def __init__(self, *args, **kwargs): > super(XMLSupport, self).__init__(*args, **kwargs) > self.x = 3 > _______________________________________________ > BangPypers mailing list > BangPypers@python.org > http://mail.python.org/mailman/listinfo/bangpypers > -- Nitin K _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers