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()?