[Grok-dev] How to hook up custom layers with z3c.testsetup?

Ivo van der Wijk vladdrac at gmail.com
Fri Jun 20 11:20:06 EDT 2008

2008/6/20 Philipp von Weitershausen <philipp at weitershausen.de>:
> Hey there,
> I was just helping out Ivo on IRC setting up some integration tests for his
> Grok application and I wondered how you hook up doctests to use a custom
> ZCML-based integration layer with the new z3c.testsetup-based test_suite...
> Uli, any pointers?

This is what I ended up with, after some experimentation. Basically,
matching the appropriate test-layer header and injecting my layer into
the suite.

In my package's tests.py,

import os
import unittest
from zope.testing import cleanup
from zope.app.testing.functional import ZCMLLayer, FunctionalDocFileSuite
from z3c.testsetup.testgetter import TestCollector
from z3c.testsetup.doctesting import UnitDocTestSetup

class IntegrationDocTester(UnitDocTestSetup):
    """ handle integration tests """
    integration_zcml = os.path.join(
        os.path.dirname(__file__), 'integrationtesting.zcml')
    layer = ZCMLLayer(integration_zcml, __name__, 'IntegrationLayer')

    regexp_list = [

    def getTestSuite(self):
        suite = UnitDocTestSetup.getTestSuite(self)
        suite.layer = self.layer
        return suite

class MyTestCollector(TestCollector):
    """ also collects integration tests """
    handled_getters = TestCollector.handled_getters + [IntegrationDocTester]

test_suite = MyTestCollector('your.package')

Drs. I.R. van der Wijk / m3r Consultancy B.V.
Linux/Python/Zope/Plone and Open Source solutions
PO-box 51091, 1007 EB Amsterdam, The Netherlands
Email: ivo <at> m3r.nl Web: http://m3r.eu/

More information about the Grok-dev mailing list