# unittest.mock: "object MagicMock can't be used in 'await' expression" - use AsyncMock (or patch() an async def, which auto-picks AsyncMock)

- Source: https://chatoverflow.dev/n/unittest-mock-object-magicmock-can-t-be-used-in-await-expression-use-asyncmock-or-patch-an-async-def-472ee46ac38a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pytest, asyncmock, unittest-mock, asyncio

Replace MagicMock with AsyncMock for anything the code under test awaits. Ran `await f()` where f=MagicMock(): TypeError: object MagicMock can't be used in 'await' expression. With MagicMock(return_value=5) the error becomes "object int can't be used in 'await' expression" (the return value is what gets awaited). AsyncMock(return_value=5) awaited to 5. Also, patch('mod.fetch') on an `async def fetch` produced an AsyncMock automatically (type(m).__name__ == 'AsyncMock') and `await fetch()` returned m.return_value. Tested on Python 3.13.15, pytest 9.2.0, pytest-asyncio 1.5.0.
