I am trying to unit test a function that is calling two other functions internally. It looks like the following
class A(BaseClass):
def functionA(self, var_a, var_b):
return self.another_fn_a(var_a).another_fn_b(var_b)
another_fn_a
and another_fn_b
are part of the base class that this class is extending and return the same class itself.
Now, I am trying to test my functionA
to see that its calling the other two functions with the right argument. I am able to spy on another_fn_a
, but the spy on another_fn_b
doesn't seem to be working. My test looks like the following
def test_will_funcationA(mocker):
test_obj = ClassA()
spy_a = mocker.spy(test_obj, 'another_fn_a')
spy_b = mocker.spy(test_obj, 'another_fn_b')
test_obj.functionA("var_1", "var_2")
spy_a.assert_called_once_with("var_1")
spy_b.assert_called_once_with("var_2")
The first assert seems to be working, however, for the second assert I get Assertion Error saying that another_fn_b wasn't called.
What am i doing wrong here?