0
# a.py
import BaseClass

class ChildClass(BaseClass):
   async def do_something():
      pass

child_instance = ChildClass()

async def method_a:
   await child_instance.do_something()
@pytest.mark.asyncio
async def test_method_a():
   mock_class = AsyncMock()
   mock_class.do_something = AsyncMock()
   mocker.patch("a.ChildClass", return_value=mock_class)  # also tried patching "a.child_instance"
   
   await method_a()

I want to mock the child class but I keep running into magicmock is not awaitable, even though I'm setting the return value to be an asyncmock. How can I get my patch of the class/and or global child instance to return an awaitable asyncmock?

michjo
  • 407
  • 2
  • 17

0 Answers0