Deriving a class from TestCase throws two errors

前端 未结 2 828
广开言路
广开言路 2020-12-10 01:08

I have some basic setup/teardown code that I want to reuse in a whole bunch of unit tests. So I got the bright idea of creating some derived classes to avoid repeating code

2条回答
  •  温柔的废话
    2020-12-10 01:18

    In BaseController's __init__ you need to call unittest.TestCase's __init__ just like you did in TestMyController.

    The call to construct a TestCase from the framework may be passing an argument. The best way to handle this for deriving classes is:

    class my_subclass(parentclass):
        def __init__(self, *args, **kw):
            parentclass.__init__(self, *args, **kw)
            ...
    

提交回复
热议问题