I have a unit test with a test-specific settings file, which includes:
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/my/file/path'
This wasn't working, so I dropped into the debugger to check the settings in the middle of running my test:
ipdb> from django.conf import settings
ipdb> settings.EMAIL_BACKEND
'django.core.mail.backends.locmem.EmailBackend'
ipdb> settings.EMAIL_FILE_PATH
'/my/file/path'
The file path setting worked, but the backend setting didn't!
Does anyone know why?
What else could I check/configure?
Is this something for a bug report?
Django 1.11
This is documented behaviour. Django replaces the regular email backend with a dummy one. You then access the "sent" emails in your tests with mail.outbox. See the docs for more info.
I believe you might be able to override the EMAIL_BACKEND for a single test or testcase with override_settings
from django.test import TestCase, override_settings
class MyTest(TestCase):
@override_settings(EMAIL_BACKEND='django.core.mail.backends.filebased.EmailBackend')
def test_email(self):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With