-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mail.outbox
not being set?
#589
Comments
See https://github.com/pytest-dev/pytest-django/blob/5da0935731d71aa347c57cd1753f51e3ba9f32d5/docs/helpers.rst#clearing-of-mailoutbox (7aee367). |
I think I'm having the same issue, so I decided to strip down my test to a basic email sending and ran it individually: def test_reset_password(mailoutbox, db, settings):
text_message = render_to_string('emails/password_reset/password_reset_successful.txt',
context={})
html_message = render_to_string('emails/password_reset/password_reset_successful.html',
context={})
subject = render_to_string('emails/password_reset/password_reset_successful_subject.txt',
context={})
email = EmailMultiAlternatives(
subject=subject,
body=text_message,
from_email="[email protected]",
to=['[email protected]']
)
if html_message:
email.attach_alternative(html_message, "text/html")
email.send()
print(settings.EMAIL_BACKEND)
assert len(mailoutbox) == 1 > assert len(mailoutbox) == 1
E assert 0 == 1
E + where 0 = len([])
accounts/tests/api/test_reset_password.py:200: AssertionError
----------------------------------------------- Captured stdout call ------------------------------------------------
django.core.mail.backends.locmem.EmailBackend
--------------------------------------------- Captured stdout teardown ---------------------------------------------- Now the cool part is if I remove the I'm stuck at the moment. |
I forgot to mention there are some tests, in the same project, where the |
I can confirm we are seeing this behaviour too with pytest-django==3.3.3 |
@bogdanpetrea |
Not sure if it is realy related, but I've found that there might be an AttributeError due to |
I have currently the problem, that mailoutbox is not empty :( EDIT: I call |
I've created a trivial test case that reproduces the issue (at least the way I'm experiencing it): https://github.com/pytest-dev/pytest-django/compare/master...koniiiik:589-mailoutbox-is-not-django-core-mail-outbox?expand=1 |
From how I've used |
Not sure if this is related to this issue, but the
|
Same. |
I have the same issue. If I use the fixture like this it fails:
Like this it works:
It took me a lot of time to discover it. I would like to help to debug this. I looked at the implementation, but I don't have a clue how to debug this. Related: https://stackoverflow.com/questions/66846621/mailoutbox-works-only-if-last-fixture |
Experiencing the same behavior as previous commentator. Using it like this doesn't work: def test_command_and_email(
mailoutbox, argument, time_machine, mocker
): But everything works as exected if I just put it at the last place. def test_command_and_email(
argument, time_machine, mocker, mailoutbox
): Argument |
Hey there, thanks for pytest-django! Appreciate all of the hard work, have used it quite a few times with no problems.
We're running into a bit of a snag where we upgraded some things and suddenly
mail.outbox
isn't retaining emails during tests. I've tried to figure out how exactly to use themailoutbox
fixture as documented here but I am having trouble using this.Right now we're testing in a class and I have tried quite a few configurations to pass
mailoutbox
fixture. I.e. I updated the ini:Not exactly sure how to use that fixture though, I tried adding the positional argument
mailoutbox
to my class methods, still not able to access it.. I am sure I am missing something simple.Would appreciate a push in the right direction -- and again, thanks so much for this project!
The text was updated successfully, but these errors were encountered: