也许我不理解箱子是如何运作的,但我从文件中了解到,在测试期间它只是收集了所有即将卸任的邮件。
I created a new project with a new application and added the following code.
from django.test import TestCase
from django.core.mail import send_mail, outbox
class SimpleTest(TestCase):
def test_basic_addition(self):
send_mail( Subject here ,
Here is the message. ,
from@example.com ,
[ to@example.com ],
fail_silently=False)
self.assertEqual( len( outbox ), 1 )
When I run python manage.py test app_name it gives an assertion error that 0 != 1. Am I doing something wrong?
Update
如果我进口django.分,邮件和邮递,这确实是多余的。 它确实发挥作用。
可以比较外箱和邮件的直接进口。 两者都带来不同的结果
from django.core import mail
from django.core.mail import send_mail, outbox
...
self.assertEqual(outbox, mail.outbox)
returns:
- []
+ [<django.core.mail.message.EmailMessage object at 0x1e1fd90>]
Maybe I ve been working to long and missing something really obvious?