I need to test that mail is sent from a Django 1.8 application; the documentation is clear on how to do this, e.g.
https://docs.djangoproject.com/en/stable/topics/testing/tools/#email-services
Here's some code which should therefore suffice:
from myapp.utils.mailutils import mail as mymail
from django.core import mail
def testThisFails(self):
user = User.objects.filter(id=1).__getitem__(0)
mymail(user,'Test Message','Test message content, please ignore...')
self.assertEquals(len(mail.outbox), 1)
self.assertEquals(mail.outbox[0].subject, 'Test Message')
...obviously, I have proper tests as well. Anyway, I get nothing but this:
self.assertEquals(len(mail.outbox), 1)
AssertionError: 0 != 1
Here's a similar question mentioning that the locmail backend needs to be used:
Django 1.3: Outbox empty during tests
So, I added this to settings.py:
TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'
if TESTING:
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
...with no luck. Even omitting the if TESTING
doesn't address the issue. Is there any means by which I can get my tests to use this backend directly?