title: Patching Async Object in Python 3.8
body: <p>I have a newbie question about mock patching async object with Python 3.8. All I am trying is to mock post() so that I can test the error handling logic, but so far I have had no luck. Could you please tell me what I did wrong? Thanks a lot.</p>
  <p><strong>main.py</strong></p>
  <pre><code>import httpx
  
  
  test_data = {&quot;id&quot;: &quot;123&quot;}
  
  class DebugClass:
      def post(self):
          try:
              async with httpx.AsyncClient() as client:
                  res = await client.post(url='http://localhost:8080', data=test_data)
              return &quot;OK&quot;
          except Exception as e:
              return &quot;NOK&quot;
  </code></pre>
  <p><strong>test_main.py</strong></p>
  <pre><code>from unittest import mock
  from unittest.mock import patch, AsyncMock
  
  
  from main import DebugClass
  
  class TestClass:
      @mock.patch('httpx.AsyncClient.post', new_callable=AsyncMock)
      def test_post(self, mock_client_post):
          mock_client_post = AsyncMock(side_effect=TimeoutError)
          debug_class = DebugClass()
          res = debug_class.post()
          assert res == &quot;NOK&quot;
  </code></pre>