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

Philipp von Weitershausen philipp at weitershausen.de
Fri Jun 20 12:38:12 EDT 2008


El 20 Jun 2008, a las 17:20 , Ivo van der Wijk escribió:
> 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')

I'm not sure why you made thos class attributes...

>    regexp_list = [
>        '^\s*:(T|t)est-(L|l)ayer:\s*(integration)\s*',
>    ]

It sucks having to reinvent the regex here :(

>    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')

It seems it's almost more work to use z3c.testsetup than just writing  
down an old school test_suite() function. It'd be nice if  
z3c.testsetup could work with arbitrary layers, like I've suggested in  
my reply to Uli.



More information about the Grok-dev mailing list