It turns out that this is by design:

http://docs.djangoproject.com/en/dev/topics/testing/#e-mail-services

This behavior is fine -- even better than the SMTP
"black hole" setup that I have.

Peace,
Andrew

On Tue, Aug 19, 2008 at 07:21:52PM -0400, Andrew D. Ball wrote:
> I've noticed that email isn't being sent during unit tests
> in Django 1.0 beta 1.  The django.core.mail.EmailMessage.send
> method returns '1' as if it had sent 1 message successfully,
> but the SMTP server doesn't get contacted at all.  The
> same thing happens with django.core.mail.send_mail.
> 
> Is this expected behavior?  Is it documented somewhere?
> 
> In versions 0.96.1 and 0.96.2 sending email with
> django.core.mail.send_mail works the same within unit
> tests and in regular views.  This is the behavior I want.
> 
> I've uploaded a small project to demonstrate what I'm talking
> about at
> http://www.ibiblio.org/adball/debugging/django/email_test.tar.bz2
> 
> If you do 
> 
> python manage.py test
> 
> no email would be sent, even though it contains a unit test that
> does
> 
>          email = EmailMessage('[unit test] subject', 'body', '[EMAIL 
> PROTECTED]', ['[EMAIL PROTECTED]'])
>          email.send(fail_silently=False)
> 
> In a view that corresponds to the ^test_email/ URL pattern,
> I have nearly identical code.  The only difference is that '[unit test]'
> is replaced with '[not unit test]'.  Email gets sent just
> fine when I run this view through a web browser.
> 
> What gives?  I'd like my unit tests to send emails.  It's fine
> if I have to add a setting or something, but it's not okay that
> I'm currently unable to get emails to be sent by unit tests.
> 
> I have a really nice "SMTP black hole" -- an SMTP server on
> a VM that delivers mail to any email address to a local mail
> spool, so the unit tests' sending emails won't hurt anything.
> 
> Peace,
> Andrew
> -- 
> ===================================
> Andrew D. Ball
> [EMAIL PROTECTED]
> Software Engineer
> American Research Institute, Inc.
> http://www.americanri.com/

-- 
===================================
Andrew D. Ball
[EMAIL PROTECTED]
Software Engineer
American Research Institute, Inc.
http://www.americanri.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to