title: How to mock just the method inside the class
body: <p>Trying to write a testcase for my class based function. This is skeleton of my class</p>
  
  <pre><code>class Library(object):
      def get_file(self):
          pass
  
      def query_fun(self):
          pass
  
      def get_response(self):
          self.get_file()
  
          response = self.query_fun()
  
          # some business logic here
          return response
  </code></pre>
  
  <p>I need to create a testcase that can mock just the  <code>query_fun</code> and do the rest. tried below but seems is not the right direction:</p>
  
  <pre><code>from unittest import mock, TestCase
  from library.library import Library
  
  class TestLibrary(TestCase):
      def setUp(self):
          self.library = Library()
  
      @mock.patch('library.library.Library')
      def test_get_response(self, MockLibrary):
          mock_response = {
              'text': 'Hi',
              'entities': 'value',
          }
          MockLibrary.query_fun.return_value = mock_response
          response = MockLibrary.get_response()
          self.assertEqual(response, mock_response)
  </code></pre>
  
  <p>What I'm expecting is to setup mock and calling <code>get_response</code> will not actually call the original <code>query_fun</code> method, but instead call the mock <code>query_fun</code>.</p>