Python - object MagicMock can't be used in 'await' expression

前端 未结 5 1158
伪装坚强ぢ
伪装坚强ぢ 2021-02-18 19:49

When I was trying to mock an async function in unittest with MagicMock, I got this exception:

TypeError: object MagicMock can\'t be used in \'await\' expr

5条回答
  •  无人及你
    2021-02-18 20:42

    shaun shia provided really good universal solution, but i found what in python 3.8 you can use just @patch('__main__.Service', new=AsyncMock)

提交回复
热议问题