__init__ for unittest.TestCase

Try this:

class TestingClass(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(TestingClass, self).__init__(*args, **kwargs)
        self.gen_stubs()

You are overriding the TestCase's __init__, so you might want to let the base class handle the arguments for you.


Install unittest2 and use that package's unittest.

import unittest2 

and then use the setupModule / tearDownModule or setupClass / tearDown class for special initialization logic

More info: http://www.voidspace.org.uk/python/articles/unittest2.shtml

Also most likely your are creating an integration test more than an unittest. Choose a good name for the Tests to differentiate them or put in a different container module.


Just wanted to add some clarifications about overriding the init function of

unittest.TestCase

The function will be called before each method in your test class. Please note that if you want to add some expensive computations that should be performed once before running all test methods please use the SetUpClass classmethod

@classmethod
def setUpClass(cls):
    cls.attribute1 = some_expensive_computation()

This function will be called once before all test methods of the class. See setUp for a method that is called before each test method.