1
我想模拟sendEmails()
方法,并想测试第二个参数是否用“[email protected]”电子邮件地址调用。如何测试模拟方法的第二个参数?
@mock.patch('apps.dbank.management.commands.optin_invites.OptinBase.sendEmails')
def test_x_send_emails(self, send_emails_mock):
oi = OptinInvitesX()
oi.compute(True, "[email protected]")
self.assertTrue(send_emails_mock.assert_called_with(???, test_email_address="[email protected]"))
我可以利用assert_called_with
但我不关心这个测试情况下,第一个参数。有没有办法说第一个参数接受任何东西?
另请参阅'mock.call_args_list'(list),'mock.call_count'(int)和'mock.called'(bool)更复杂的案例 – wim 2014-10-27 17:22:31
是的,它的工作原理类似'self.assertEquals(args [0 ] [1] ['test_email_address'],“[email protected]”)。它不漂亮。我希望有更好的办法。如果没有更好的解决方案,我会将问题留待一天,我会接受。非常感谢 – Houman 2014-10-27 18:02:58