0

For example, I have functions that are working with strings. And I would like to create an unittest, which is checking the functions. Sometimes, tests are identical, so I was thinking for creating BaseCase, which is do similar jobs for all functions. And function is an argument for this BaseCase. How can I do it? I came up with something like this...

class BaseTestCase (unittest.TestCase):
    def setUp(self):
        self.newMethod = None

    def testMethod (self):
        if self.newMethod:
            self.assertEqual (1, self.newMethod())

def someF():
    return 1

class SomeTestCase (BaseTestCase):
   def setUp(self):
       self.newMethod = someF

if __name__ == "__main__":
    unittest.main()

It is working as I need, but it fire one extra test (with all ok in it) for test method. Is it possible to do the same job via _init__ and super()?

EvilAnton
  • 353
  • 1
  • 2
  • 9
  • 1
    There doesn't seem to be any easier (other than using class members). Have a look a this possible duplicate: [Instantiate Python unittest.TestCase with arguments](http://stackoverflow.com/questions/17260469/instantiate-python-unittest-testcase-with-arguments) – Rod Jan 06 '15 at 21:59
  • Oh, thanks! I somehow skiped this queestion! – EvilAnton Jan 06 '15 at 22:07

0 Answers0