title: Confirming function calls inside a function I'm unittesting with mock module
body: <p>I have a function I'm writing unit tests for.  I'm trying to assert that a number of functions were called with the proper arguments given the input argument.  For example, the function I'm unit testing is in a file called validate.py</p>
  
  <pre><code>def function_to_test(arg1):
      print 'return2: ', _sub_function_1()
      arg1 = _sub_function_1(arg1)
      arg1 = _sub_function_2(arg1)
      arg1 = _sub_function_3(arg1)
      return arg1
  
  
  def _sub_function_1(arg1):
      pass
  
  def _sub_function_2(arg1):
      pass
  
  def _sub_function_3(arg1):
      pass
  </code></pre>
  
  <p>I have my unit tests in a file called dotest.py, </p>
  
  <pre><code>import validate
  import unittest
  import mock
  
  class TestFunctionToTest(unittest.TestCase):
  
      @mock.patch('validate._sub_function_1')
      def test_basic(self, m_sub_function_1):
          m_sub_function_1 = mock.Mock(return_value='rv_sf1')
          dum_arg1 = 'dum'
          out = validate.function_to_test(dum_arg1)
          print 'called?: ', m_sub_function_1.called
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>The results of running this test are, </p>
  
  <pre><code>run -i dotest.py
  return2:  &lt;MagicMock name='_sub_function_1()' id='4502266128'&gt;
  called?:  False
  .
  ----------------------------------------------------------------------
  Ran 1 test in 0.001s
  
  OK
  </code></pre>
  
  <p>For some reason the return value defined for the mock function is not being recognized in the call to <code>_sub_function_1</code>.  I want to check if this function is actually called in <code>function_to_test</code>.  Any insight from the mock gurus?</p>