Jan-Wijbrand Kolman wrote:
> Zope.sendmail explains in its README.txt that the developer using
> zope.sendmail should himself take care of not sending emails (by setting
> up a test layer for example, that would register a no-op IMailDelivery
> utility).
Why not just use testfixtures [1] and Mock [2] to replace the SMTP class
in your testcase?
from mock import Mock
from testfixtures import replace
@replace('smtplib.SMTP',Mock())
def test_mystuff(self):
...
That way you can check the right smtp calls are made, if you want to,
and there's no chance of mail being sent?
If you're doing a lot of tests, you might want to do:
from mock import Mock
from testfixtures import Replacer
class MyTests(TestCase):
def setUp(self):
self.r = Replacer
self.r.replace('smtplib.SMTP',Mock())
def tearDown(self):
self.r.restore()
This latter technique would probably work in a Layer too...
cheers,
Chris
[1] http://pypi.python.org/pypi/testfixtures
[2] http://pypi.python.org/pypi/mock
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
_______________________________________________
Zope-Dev maillist - [email protected]
http://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )