#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 Natalia Bidart):
Replying to [comment:3 Baptiste Mispelon]:
> 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.
Thank you for these details, they definitely help to clarify the original
report. I do think that if a project customizes the email backend on a
per-email manner, it's the project's tests responsibility to provide a
mock for it (even part of the test case should include asserting that the
right backend is used in the right place, I guess).
> 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.
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`.
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).
Lastly, I agree with you Baptiste that in a way this could be a duplicate
of the not-yet-existing ticket for multiple email backends. I have pinged
the author of [https://github.com/django/django/pull/13728 the related PR]
but they do not have time at the moment to push the feature further. In
order for that to progress, we would need someone to create the ticket and
hopefully take ownership of the feature to progress it.
--
Ticket URL: <https://code.djangoproject.com/ticket/35118#comment:4>
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/0107018d12d4e6b2-fae75648-209b-4d48-8e3a-913cace7aeab-000000%40eu-central-1.amazonses.com.