[Zope-dev] zope.sendmail and testing

Jan-Wijbrand Kolman janwijbrand at gmail.com
Tue Aug 25 08:48:57 EDT 2009


Hello,

We're using zope.sendmail to send mail from our applications. These 
applications are built on top of a more generic application library. It 
is this application library that depends on zope.sendmail. This 
application library listens for certain events and then can decide to 
send out an email.

Obviously, when running the tests for the concrete application no mail 
is allowed to be actually sent.

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).

I had hoped that somehow zope.sendmail would automagically "detect" it 
is used during test runs and then would not send out any mails.

I dug around in zope.testing and found the cleanup module that seems to 
provide (if I understand correctly) a global registry of things to 
cleanup after tests. I wonder if this could be extended to also be able 
to register routines for globally setting up stuff - in this case it 
could stub the mail delivery so that never ever any mail is actually 
send out when running tests.

Questions:

1) how do others make sure that applications that directly or indirectly 
trigger sending mails do not actually send during testing?

2) am I on the right track thinking a "set up" equivalent of 
zope.testing.cleanup could be useful for these cases?

kind regards,
jw

--
Jan-Wijbrand Kolman



More information about the Zope-Dev mailing list