Chris Withers wrote:
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?
My point is that I have to make sure the fixtures/mocking is done even in indirect consumers of zope.sendmail. What I mean is, if I run the tests of my application Foo, that uses an application library MyLib where this MyLib library listens for events that can trigger email being send, I need to *not forget* to use these fixtures or mocks in the test setup of Foo. Even if the code of Foo does not itself call zope.sendmail. I had hoped there would be a way for either zope.sendmail, or perhaps for MyLib, to make sure that no mail is ever send when running tests of Foo.
This latter technique would probably work in a Layer too...
Right, that might work - I would need to define a test layer in MyLib and not forget to use this base layer for the tests for Foo. It would be slightly better, but it is still something I or a team member could forget. Generally that would not be so much of a problem, however I would hate to unintentionally send out mail... Still I wonder about zope.testing.cleanup... Thanks for the replies so far! regards, jw