I am simply not experienced enough in Python OO programming to know how this is done: If I have several classes that are subclasses of a unittest.TestCase
subclass. How should the superclass' methods reference variables of the subclasses when the latter call these methods? Let me try to illustrate it with this, probably wrong, example:
import unittest
class TestSuper(unittest.TestCase):
def test_method(self):
# do something, e.g.
pass
class TestSub1(TestSuper):
def setUp(self):
self.some_parameter = 1
class TestSub2(TestSuper):
def setUp(self):
self.some_parameter = 2
if __name__ == '__main__':
unittest.main()
Now, I cannot figure out how to correcty reference TestSub1.parameter
or TestSub2.parameter
, respectively, when TestSuper.test_method
is called from the subclasses.
I am inspired by https://stackoverflow.com/a/25695512/865169, but here I am trying achieve having multiple test cases that do the same but only differ in their set-up. I can of course achieve all this by just copy-pasting my test case definitions, but I find that bad coding practice.