title: Python Mock Patch multiple methods in a class
body: <p>Im trying to patch multiple methods in a class. Here is my simplified set up</p>
  
  <p>Hook.py is defined as </p>
  
  <pre><code>class Hook():
      def get_key(self):
          return "Key"
  
      def get_value(self):
          return "Value"
  </code></pre>
  
  <p>HookTransfer.py defined as </p>
  
  <pre><code>from Hook import Hook
  
  class HookTransfer():
      def execute(self):
          self.hook = Hook()
          key = self.hook.get_key()
          value = self.hook.get_value()
          print(key)
          print(value)
  </code></pre>
  
  <p>I want to mock the methods get_key and get_value in the Hook class. The following works i.e. prints New_Key and New_Value</p>
  
  <pre><code>from HookTransfer import HookTransfer
  import unittest
  from unittest import mock
  
  class TestMock(unittest.TestCase):
      @mock.patch('HookTransfer.Hook.get_key', return_value="New_Key")
      @mock.patch('HookTransfer.Hook.get_value', return_value="New_Value")
      def test_execute1(self, mock_get_key, mock_get_value):
          HookTransfer().execute()
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>However this does not. It prints <code>&lt;MagicMock name='Hook().get_key()' id='4317706896'&gt;</code> and <code>&lt;MagicMock name='Hook().get_value()' id='4317826128'&gt;</code></p>
  
  <pre><code>from HookTransfer import HookTransfer
  import unittest
  from unittest import mock
  
  class TestMock(unittest.TestCase):
      @mock.patch('HookTransfer.Hook', spec=True)
      def test_execute2(self, mock_hook):
          mock_hook.get_key = mock.Mock(return_value="New_Key")
          mock_hook.get_value = mock.Mock(return_value="New_Value")
          HookTransfer().execute()
  
  if __name__ == '__main__':
      unittest.main()
  </code></pre>
  
  <p>Intuitively it seems like the second one should work too but it doesnt. Could you help explain why it does not. I suspect it has something to do with <a href="http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch" rel="noreferrer">"where to patch"</a> but Im unable to get clarity.</p>