title: How patch a method being called from an instance in python
body: <p>I am trying to write a unittest for my file <strong>abc.py</strong>. 
  I am not able to set a return value for a method being called from a class instance. </p>
  
  <p>Here is my file:</p>
  
  <p><strong>abc.py</strong></p>
  
  <pre><code>class ABC(object):
      def __init__(self):
          pass
  
      def fetch_id(self):
          id = # from somewhere
          return id
  
  def main():
      module = someRandomClass()
      client = ABC()
      account_id = client.fetch_id()
      module.save(account_id=account_id)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>And here is the test file</p>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>import mock
  import abc
  
  @mock.patch('abc.ABC')
  @mock.patch('someRandomClass')
  def test_all(module, mock_abc):
      abc.main()
      module.assert_called_with()
  
      client = mock_abc.return_value
      mock_abc.assert_called_with()
  
      client.fetch_id.return_value = '12345667'
      module.save.assert_called_with(account_id='12345667')
  </code></pre>
  
  <p>Getting the following error:</p>
  
  <pre><code>AssertionError: Expected call: save(account_id='12345667')
  Actual call: save(account_id=&lt;MagicMock name='ABC().fetch_id()' id='4507253008'&gt;)
  </code></pre>