Django 1.3:测试期间发件箱为空
也许我不明白发件箱是如何工作的,但从文档中我了解到它只是在测试期间捕获所有外发邮件。
我使用新应用程序创建了一个新项目,并添加了以下代码。
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.',
'[email protected]',
['[email protected]'],
fail_silently=False)
self.assertEqual( len( outbox ), 1 )
当我运行 python manage.py test app_name 时,它给出了一个断言错误 0 != 1。我做错了什么吗?
更新
嗯,如果我导入 django.core.mail 并使用 mail.outbox 它确实有效,这很奇怪。
尝试比较 outbox 和 mail.outbox 的直接导入,它们都给出不同的结果
from django.core import mail
from django.core.mail import send_mail, outbox
...
self.assertEqual(outbox, mail.outbox)
返回:
- []
+ [<django.core.mail.message.EmailMessage object at 0x1e1fd90>]
也许我已经工作了很长时间并且错过了一些真正明显的东西?
Maybe I don't understand how outbox works but from the documentation I understood that it just catches all outgoing mail during testing.
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.',
'[email protected]',
['[email protected]'],
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
Well this is weird if I import django.core.mail and use mail.outbox it does work.
Tried to compare the direct import of outbox and mail.outbox and they both give different results
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许我真的应该阅读文档。
https://docs.djangoproject.com/en/dev /主题/测试/工具/#email-services
Maybe I should actually read the documentation.
https://docs.djangoproject.com/en/dev/topics/testing/tools/#email-services