title: How correctly mock class dependencies?
body: <p>I've recently started learning how to use mock from <code>unittest</code> library and encountered a problem figuring out how to correctly mock class dependencies.
  Below is the example i'm trying to mock</p>
  <p>client.py</p>
  <pre><code>class HttpClient:
  
      def request(self, method, url, params = None):
          if method == &quot;GET&quot;:
              return requests.get(url)
          elif method == &quot;POST&quot;:
              return requests.post(url, body=params)
  </code></pre>
  <p>Here I inject the HttpClient object into the Post class</p>
  <p>As I understood I need to mock <code>self.client.request</code> and this can be replaces with requests get or maybe in some other way?</p>
  <p>data.py</p>
  <pre><code>class Post:
  
      def __init__(self, client: HttpClient):
          self.client = client
          self.base_url = &quot;https://jsonplaceholder.typicode.com&quot;
  
      def get_posts(self, amount):
          response = self.client.request(method=&quot;GET&quot;, url=f&quot;{self.base_url}/posts/{amount}&quot;)
  
          if response.ok:
              return response.json()
  
          return response.status_code
  </code></pre>
  <p>And now the testing part</p>
  <p>test_data.py</p>
  <pre><code>class TestPost(unittest.TestCase):
  
      @patch('app.client.HttpClient')
      def setUp(self, module):
          self.mock_http = MagicMock(autospec=HttpClient)
          self.mock_post = Post(self.mock_http)
  
      @patch.object(requests, 'get')
      def test_get_posts(self, mock_data):
          mock_data.return_value = {
              'postId': 1,
              'title': 'My title',
              'description': 'Post description'
          }
  
          response = self.mock_post.get_posts(1)
  
          assert response['postId'] == 1
  </code></pre>
  <p>So does when I set <code>mock_data.return_value</code> it actually replace the original response that is being called here <code>response = self.mock_post.get_posts(1)</code> or not?</p>
  <p>Maybe someone could explain how this exactly works</p>
  <p>Thank You!</p>