Skip to content

Instantly share code, notes, and snippets.

@anandology
Created May 24, 2021 03:42
Show Gist options
  • Save anandology/f3be96a32e23507c1284d23b6ec76084 to your computer and use it in GitHub Desktop.
Save anandology/f3be96a32e23507c1284d23b6ec76084 to your computer and use it in GitHub Desktop.
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=['[email protected]'],
sender='[email protected]',
subject='Test Mail',
message='Dear Test, welcome!',
delayed=False)
assert len(emails) == 1
email = emails[0]
assert email['from_addr'] == '[email protected]'
assert email['to_addrs'] == ['[email protected]']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment