我在设置单元测试时遇到了很多困难。我一直在使用补丁,但它的行为并不像预期的那样完全。为什么assert_called_with失败?
我在我的测试功能的顶部装饰: @mock.patch('WarningFactory.WarningAPIUpdate') @mock.patch('WarningFactory.SomethingElse') def test_send_tc_update(self, other_mock, api_mock):
然而,当我的函数结束时,我尝试做如下声明:
api_mock.send_warning.assert_called_with('IDQ20026', 'IDQ20026')
它失败
我知道应该通过因为我跑
print api_mock.mock_calls
给人
[call(u'test_api'), call().send_warning('IDQ20026', 'IDQ20026'), call().send_warning('IDQ24500', 'IDQ24500')]
我可以清楚地看到send_warning方法被调用正确的价值观,所以为什么我的断言失败?
你有没有想过这一个?有同样的问题 – learningKnight
@learningKnight添加了一个答案,希望有所帮助。 – user3559247