[BangPypers] issues using constructor in unittest
Nitin Kumar
nitin.nitp at gmail.com
Mon Mar 14 10:30:01 CET 2011
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.kabra at gmail.com> wrote:
> On Mon, Mar 14, 2011 at 1:56 PM, Nitin Kumar <nitin.nitp at 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 at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
Nitin K
More information about the BangPypers
mailing list