[Zope-Coders] Help with Unit Testing

Chris Withers chrisw@nipltd.com
Mon, 12 Aug 2002 15:11:04 +0100


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? ;-)

 > +# XXX: 2002/08/12:  Another thumb-rule:  don't write to the filesystem
 > +#       as part of a unittest (failure modes are too hard to track down,

How else are you supposed to test whether changes on the file system are
noticed? In particular, FSDV's have been dodgy in this area for ages.
How do you suggest we test them?

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

Again, I'm not sure why this requirement was only brought to light for these
tests, which have been in the testsuite for many months now.

Will these requirements also be applied to the rest of the Zope testsuite?

 > +    #
 > +    # XXX: 2002/08/12: These tests "smell funny";  they are perhaps too
 > +    #       "white box"?  #   (and two of them fail on Linux, as well;
 > +    #       you are hardwiring assumptions about the shape of
 > +    #       SOFTWARE_HOME/INSTANCE_HOME).

No. The point is that .zexps _can_ contain any of these and so we should be able
to deal with them rather than have the nasty 'empty directory view' symptoms. My
mistake was not providing a 'do nothing' option for when nothing can sensibly be
done, as in the case of PRODUCTS_PATH setups.

Am I wrong in this understanding?

 > +# XXX: 2002/08/12:  Tests shouldn't depend on one another;  common
 > +#       stuff like this should be factored out into a utilty module.
 > +#
 >  from test_DirectoryView import _registerDirectory
 >  from test_DirectoryView import _prefix

Was tempted, but since only the FSDV tests use them it seemed overkill. I'll
move them to CMFCore.tests.base.utils

 > +#
 > +# XXX: 2002/08/12:  don't write to the filesystem (see test_DirectoryView)

See earlier comments ;-)

cheers,

Chris