I'm trying to create a test case using the Unittest framework in python, where I can provide arguments to both setUp and test_case functions.
So far I've created a Fixture class, which inherits from TestCase, initialized a variable in the constructor which can be passed as an argument later on (self.option).
Later on in another class, I've used the super() function to initialize the __init__ function of the parent class, and I'm also providing an argument (self.option) that I'm hoping gets through to both setUp and test_case functions in the parent class.
Eventually, I'm just calling the inherited self.test_case() function, which also invokes the setUp function of the same class.
The code looks like this:
from unittest import TestCase
class Fixture(TestCase):
def __init__(self, option):
self.option = option
super(Fixture, self).__init__(self.option)
def setUp(self):
print(f'\nSetting up option {self.option}')
def test_case(self):
print(f'Testing option {self.option}')
class Runner(Fixture):
def __init__(self):
self.option = 'one'
super().__init__(self.option)
def case(self):
self.test_case()
The test passes and I get the following output:
Process finished with exit code 0
PASSED [100%]
Setting up option test_case
Testing option test_case
However, in the printouts, I was expecting to see something like Setting up option one, but I'm getting Setting up option test_case instead - with function name as a received variable, as it seems.
What's wrong here? What would be the correct approach to solve this?