[Product-Developers] Re: Test setup in ZopeSkel

Ross Patterson me at rpatterson.net
Wed Aug 20 20:34:08 UTC 2008


Daniel Nouri <daniel.nouri at gmail.com>
writes:

> Maurits van Rees writes:
>
>> I can imagine that the lines for loading the zcml *are* needed there
>> because then you can ensure that the zcml gets loaded before calling
>> installPackage.  Is this perhaps the only good reason for including
>> those zcml lines in that specific case only?
>
> Not going into the TANGLED MESS that Plone test setups have arrived to,
> I believe that you'll need to load your ZCML if you depend on the
> registrations therein in your test.  That is, AFAIK, noone's going to
> implicitely load the site.zcml for you, which is a good thing.
>
> And yes, being able to run the tests independently of the specific
> buildout you're using it with is quite a feature.

The PloneSite layer depends on the ZCML layer which does indeed load
site.zcml.  So if the ZCML your test fixture requires is included by
loading site.zcml for the instance and you're using the layer PloneSite
(which PloneTestCase does), then you don't need to load it explicitly in
your test fixture.  At least that's my understanding.  :)

BTW, I'm very much in favor of reducing the boilerplate in ZopeSkel,
particularly the testing boilerplate.  Here's the boilerplate I use for
a testing.py module:

    from Testing import ZopeTestCase
    from Products.PloneTestCase import ptc
    
    from collective.testcaselayer import ptc as tcl_ptc
    
    ptc.setupPloneSite()
    
    class InstallLayer(tcl_ptc.BasePTCLayer):
    
        def afterSetUp(self):
            ZopeTestCase.installProduct('foo')
            self.addProfile('foo:default')
    
    install_layer = InstallLayer([ptc.PloneTestCase.layer])

Then in tests.py all I need is:

    import unittest
    from zope.testing import doctest
    from Testing import ZopeTestCase
    from Products.PloneTestCase import ptc
    
    from foo import testing
    
    def test_suite():
        suite = ZopeTestCase.ZopeDocFileSuite(
            'README.txt',
            optionflags=(
                doctest.NORMALIZE_WHITESPACE|
                doctest.ELLIPSIS|
                doctest.REPORT_NDIFF),
            test_class=ptc.PloneTestCase)
        suite.layer = testing.install_layer
        return unittest.TestSuite([suite])
    
    if __name__ == '__main__':
        unittest.main(defaultTest='test_suite')

I find collective.testcaselayer to be really useful and has made all my
test fixtures *much* simpler and more reliable.  So far, I haven't head
that it's been of much use to anyone else, so maybe it's just me.  :)
But if any of you can take a look at it, try it out and give me some
feedback, that would be great.

Ross





More information about the Product-Developers mailing list