[Zope-dev] zope.sendmail and testing

Marius Gedminas marius at gedmin.as
Wed Aug 26 10:31:52 EDT 2009


On Tue, Aug 25, 2009 at 05:12:53PM +0200, Jan-Wijbrand Kolman wrote:
> 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.

But MyLib cannot send email if your test fixture doesn't set up and
register a fully-functional email-sending utility!  Find the place where
your test fixtures do that and replace it with a stub no-email-sending
utility.

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

Some kind of a global switch to unconditionally disable email delivery
in zope.sendmail would be useful sometimes, but I'm afraid of it
clouding the issue too much.

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

You cannot really depend on the order of cleanup handlers.  There
already is a cleanup handler that clears the whole component registry,
including any and all email utilities.  PlacelessSetup invokes all
cleanup handlers.

If your tests use PlacelessSetup (and unit tests generally do), and if
they can send mail, then it means you're registering an email utility
after the cleanup handlers have run, and therefore a cleanup handler
cannot possibly disable it.

Functional tests that want to preserve some kind of component
configuration between tests cannot use PlacelessSetup (or CleanUp),
since the aforementioned cleanup handler would clear the component
registry and break all your tests.

Marius Gedminas
-- 
http://pov.lt/ -- Zope 3 consulting and development
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20090826/d13482e2/attachment.bin 


More information about the Zope-Dev mailing list