My Python version is 2.6.
I would like to execute the test setUp method only once since I do things there which are needed for all tests.
My idea was to crea
I'm using Python 3 and found that the cls reference is also available in the setup method and so the following works:
class TestThing(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.thing = Thing() # the `thing` is only instantiated once
def setup(self):
self.thing = cls.thing # ...but set on each test case instance
def test_the_thing(self):
self.assertTrue(self.thing is not None)