I'm trying to understand what happens when doing multiple inheritance using a unittest.TestCase
class.
MyTest_DoesWork
outputs what I expect, this is both setUp()
and tearDown()
being triggered. This is not happening with MyTest_DoesNotWork
. Why is this happening? Any clue?
import unittest
class MyClassTest1(object):
def setUp(self):
print 'Setting up', self.__class__
def test_a1(self):
print "Running test_a1 for class", self.__class__
def test_a2(self):
print "Running test_a2 for class", self.__class__
def tearDown(self):
print 'Tearing down', self.__class__
class MyClassTest2(object):
def setUp(self):
print 'Setting up', self.__class__
def test_b1(self):
print "Running test_b1 for class", self.__class__
def test_b2(self):
print "Running test_b2 for class", self.__class__
def tearDown(self):
print 'Tearing down', self.__class__
class MyTest_DoesNotWork(unittest.TestCase, MyClassTest1, MyClassTest2):
"""
Output:
Running test_a1 for class <class '__main__.MyTest_DoesNotWork'>
.Running test_a2 for class <class '__main__.MyTest_DoesNotWork'>
.Running test_b1 for class <class '__main__.MyTest_DoesNotWork'>
.Running test_b2 for class <class '__main__.MyTest_DoesNotWork'>
"""
pass
class MyTest_DoesWork(MyClassTest1, MyClassTest2, unittest.TestCase):
"""
Output:
Setting up <class '__main__.MyTest_DoesWork'>
Running test_a1 for class <class '__main__.MyTest_DoesWork'>
Tearing down <class '__main__.MyTest_DoesWork'>
.Setting up <class '__main__.MyTest_DoesWork'>
Running test_a2 for class <class '__main__.MyTest_DoesWork'>
Tearing down <class '__main__.MyTest_DoesWork'>
.Setting up <class '__main__.MyTest_DoesWork'>
Running test_b1 for class <class '__main__.MyTest_DoesWork'>
Tearing down <class '__main__.MyTest_DoesWork'>
.Setting up <class '__main__.MyTest_DoesWork'>
Running test_b2 for class <class '__main__.MyTest_DoesWork'>
Tearing down <class '__main__.MyTest_DoesWork'>
"""
pass
if __name__ == "__main__":
unittest.main()