title: Spy chained functions in Python
body: <p>I am trying to unit test a function that is calling two other functions internally. It looks like the following</p>
  
  <pre><code>class A(BaseClass):
      def functionA(self, var_a, var_b):
          return self.another_fn_a(var_a).another_fn_b(var_b)
  </code></pre>
  
  <p><code>another_fn_a</code> and <code>another_fn_b</code> are part of the base class that this class is extending and return the same class itself.</p>
  
  <p>Now, I am trying to test my <code>functionA</code> to see that its calling the other two functions with the right argument. I am able to spy on <code>another_fn_a</code>, but the spy on <code>another_fn_b</code> doesn't seem to be working. My test looks like the following</p>
  
  <pre><code>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")
  </code></pre>
  
  <p>The first assert seems to be working, however, for the second assert I get Assertion Error saying that another_fn_b wasn't called.</p>
  
  <p>What am i doing wrong here?</p>