#35118: Mention test-suggestions when specific email-backend is used
-------------------------------------+-------------------------------------
Reporter: jecarr | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Mail) | Version: 5.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jecarr):
* status: closed => new
* resolution: invalid =>
Comment:
Replying to [comment:4 Natalia Bidart]:
Thanks for the discussion on this.
> If a custom but single backend is needed across the project, the
recommendation would be to define the custom backend class and point the
`EMAIL_BACKEND` setting to it (as per
[https://docs.djangoproject.com/en/5.0/topics/email/#defining-a-custom-
email-backend these docs]). In this case, the previously linked
`setup_test_environment` would do the right thing by overriding the
`EMAIL_BACKEND` setting to be `locmem`.
I believed I was following the docs anyway: I didn't change the
`EMAIL_BACKEND` setting in my project. I just used an
[https://docs.djangoproject.com/en/5.0/topics/email/#smtp-backend SMTP
EmailBackend] instance as my `connection` parameter when creating an
`EmailMessage` or to call `connection.send_messages()`.
This then mirrors Baptiste Mispelon's code example on how my test cases
sent actual emails:
{{{
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from django.test import SimpleTestCase
def send_message():
mail.send_mail(
"Subject here",
"Here is the message.",
"[email protected]",
["[email protected]"],
fail_silently=False,
connection=EmailBackend() # comment out to pass test
)
class ReproductionTestCase(SimpleTestCase):
def test_custom_backend_bypass_locmem(self):
send_message()
self.assertEqual(len(mail.outbox), 1)
}}}
> We may consider adding a note in the docs, but the clarification should
be quite explicit about *when* a backend override is needed in tests,
since the proposed PR could be read as that the tests always need an
override (when, in practice, they almost never need one).
I thought I was explicit about when the override is needed? My PR begins
with "If your application defines a different email backend to be used
[other than locmem]". This was applicable to my scenario above because I
was defining an SMTP backend. I did link
[https://github.com/django/django/pull/17741 the PR] when I opened my
ticket but it seems to be unlinked at time of writing.
Replying to [comment:1 Baptiste Mispelon]:
> I think we should try to find a systematic solution to the problem but
if that's too hard we should at least document quite loudly that one must
pay attention when using a custom `connection`.
I therefore think this point still stands rather than this being about
multiple email backends (do point out if I'm misunderstanding how that
links!).
--
Ticket URL: <https://code.djangoproject.com/ticket/35118#comment:5>
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/0107018d16f9945e-7cb47087-70ee-4522-9c7b-9042ed9e7713-000000%40eu-central-1.amazonses.com.