[TIP] Inheritance of TestClasses?

Williams, James P. {Jim} (JSC-CD4)[SGT, INC] james.p.williams at nasa.gov
Mon Sep 9 15:42:02 PDT 2019


You have to inherit from unittest.TestCase, not object.  Also, there's no reason you can't have an __init__() method.  Just make sure you forward arguments to your parent.  This should work on Python 2 or 3.

    class TestClass1(unittest.TestCase):
        def __init__(self,*args,**kwArgs):
            super(TestClass1,self).__init__(*args,**kwArgs)
            # initialize...

        # ...etc...

    class TestClass2(TestClass1):
        def __init__(self,*args,**kwArgs):
            super(TestClass2,self).__init__(*args,**kwArgs)
            # initialize...

        # ...etc...

Good luck.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20190909/ea8ea64f/attachment.htm>


More information about the testing-in-python mailing list