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