#35118: Mention test-suggestions when specific email-backend is used
-------------------------------------+-------------------------------------
Reporter: jecarr | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (Mail) | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Baptiste Mispelon):
Replying to [comment:2 Natalia Bidart]:
> [...] Baptiste, were you able to reproduce? Could you share a sample
test project?
>
> I'll be closing as invalid for now, but if I'm missing something, please
provide as much details as possible so we can re-triage. Thank you!
Sorry if I accepted the ticket a bit eagerly, I haven't done triaging in a
while. Here's a testcase that I think reproduces the issue being reported
by jecarr:
{{{#!python
from django.core import mail
from django.core.mail.backends.base import BaseEmailBackend
from django.test import SimpleTestCase
class BrokenEmailBackend(BaseEmailBackend):
"""
A custom email backend that throws an exception when sending a message
"""
def send_messages(self, messages):
raise Exception("no sending allowed")
# in reality, this function would be burried deep somewhere in user code
def send_message():
mail.send_mail(
"Subject here",
"Here is the message.",
"[email protected]",
["[email protected]"],
fail_silently=False,
connection=BrokenEmailBackend()
)
class ReproductionTestCase(SimpleTestCase):
def test_custom_backend_bypass_locmem(self):
send_message()
self.assertEqual(len(mail.outbox), 1) # fails with exception
being raised from backend
}}}
You do have a point that a user who manually instantiates an email backend
should also have the responsibility to mock it in their tests, but I feel
that this is still a surprising effect (it surprised me for what it's
worth).
Manually instantiating a backend is the documented way (and as far as i
know, the only one) to use a different email backend for specific
messages, so it should either be made safe or at least the documentation
should be clearer that test should be careful and mock accordingly.
My preferred solution would be the named backend settings I linked to in
my earlier comment, but I understand that's a completely different beast,
and I don't want to stand in the way of the improvements suggested here.
--
Ticket URL: <https://code.djangoproject.com/ticket/35118#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018d129c3cd8-bc315f91-85b2-4b38-b0e4-dfe2c730bf21-000000%40eu-central-1.amazonses.com.