Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
email test using py.test
def test_sendmail(monkeypatch):
emails = []
def mock_sendmail(self, from_addr, to_addrs, msg, mail_options=(), rcpt_options=()):
emails.append(dict(from_addr=from_addr, to_addrs=to_addrs, msg=msg))
monkeypatch.setattr(smtplib.SMTP, "sendmail", mock_sendmail)
frappe.sendmail(
recipients=['test@example.com'],
sender='noreply@example.com',
subject='Test Mail',
message='Dear Test, welcome!',
delayed=False)
assert len(emails) == 1
email = emails[0]
assert email['from_addr'] == 'noreply@example.com'
assert email['to_addrs'] == ['test@example.com']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment