[Zope-Coders] Help with Unit Testing
Shane Hathaway
shane@zope.com
Mon, 12 Aug 2002 12:09:11 -0400
Chris Withers wrote:
> Tres Seaver wrote:
> > +#
> > +# XXX: 2002/08/12 Generic rule: *don't* do imports of the
> module-under-test
> > +# at module scope in the unittest; failure here suppresses
> information!
> > +#
> > from Products.CMFCore.DirectoryView import registerDirectory
> > from Products.CMFCore.DirectoryView import addDirectoryViews
> > from Products.CMFCore.DirectoryView import DirectoryViewSurrogate
>
> Not sure I follow you here. This pattern is used all over the place. I
> can see
> what you're driving at but I'm not sure why these tests were picked out
> as an
> example? Should we change tests like these everywhere? will we? ;-)
It's a new pattern that seems logical. Your tests were picked out only
because they are new. :-) There are other patterns known to be bad in
unit tests (like "assert" statements), but we haven't taken the time to
clean up older tests, partly because we're not sure we've discovered all
the right patterns yet.
> > +# and it should be possible to run them *anywhere*, including in
> > +# a setup where the files / directories are readonly.
>
> ..I don't think it's possible for this to be the case. Lots of the Zope
> tests
> (ZCatalog indexes, ZODB, etc) write to files.
Do they? If you import the "Testing" package before importing "Zope",
Zope.app() gives you a DemoStorage instead of a FileStorage.
Shane