python - How to test for the second parameter of a mocked method? -
python - How to test for the second parameter of a mocked method? -
i trying mock sendemails() method , test if sec parameter called "test@test.com" email address.
@mock.patch('apps.dbank.management.commands.optin_invites.optinbase.sendemails') def test_x_send_emails(self, send_emails_mock): oi = optininvitesx() oi.compute(true, "test@test.com") self.asserttrue(send_emails_mock.assert_called_with(???, test_email_address="test@test.com")) i utilise assert_called_with don't care first parameter test case. there way take first parameter?
i couldn't figure out how when attempting same thing.
here hacky workaround:
from mock import magicmock class yesman(object): def __eq__(self, other): homecoming true = yesman() mock = magicmock() mock(x=123, y=456) mock.assert_called_once_with(x=anything, y=456) an alternative @ attribute
>>> mock.call_args call(y=456, x=123) and build assertions on object.
python unit-testing python-mock
Comments
Post a Comment