0

I was trying to run all my unit test unit from the unit test object:

def run_unit_test_for_user(f,*args,**kwargs):
    test = Test_code(f,args,kwargs)
    test.run()

class Test_code(unittest.TestCase):
    def __init__(self,f,args,kwargs):
        self.f = f, ...etc...
        pass

    def test1(self):
        #do stuff

    def test2(self):
        #do stuff

    def test3(self):
        #do stuff

however I get errors like:

Traceback (most recent call last):
  File "my_module.py", line 191, in <module>
    user_test.run_unit_test_for_user(Test_code)
  File "/Users/user/path/my_module.py", line 6, in run_unit_test_for_user
    test.run()
  File "/Users/user/miniconda3/envs/eit/lib/python3.6/unittest/case.py", line 576, in run
    testMethod = getattr(self, self._testMethodName)
AttributeError: 'Test_code' object has no attribute '_testMethodName'

why is it so difficult? I need to feed code/variables etc from another module so I dont want to do:

unittest.main()

because I need to pass arguments from other already running code.

I am not using command line nor do I wish, please don't suggest it.

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • does [this](https://stackoverflow.com/questions/7562775/deriving-a-class-from-testcase-throws-two-errors) help at all? – an0o0nym Jun 25 '17 at 00:35
  • @an0o0nym I think I realized that I have to build a unit test for each test I want, which is really annoying, I dont understand why I need to do that, I just want one object. Doing that makes me have to re-write my `__init__` like so many times, so unnecessary... – Charlie Parker Jun 25 '17 at 01:05
  • @an0o0nym to answer more directly my current code has what that suggests but I don't understand why I need to do that, its so much uglier and verbose and repetitive. – Charlie Parker Jun 25 '17 at 01:06

0 Answers0