如何断言将异常作为参数的被调用函数?
在我的代码中:
def mainFunc:
# ...
raise ValueError('valueError')
# ...
except Exception as e:
myFunc(e)
测试中:
from unittest.mock import patch
# ...
@patch('main.myFunc')
def test(mock):
mainFunc()
mock.assert_called_with(ValueError('valueError'))
我得到了:
AssertionError: expected call not found.
Expected: myFunc(ValueError('valueError'))
Actual: myFunc(ValueError('valueError'))