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

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


El 20 Jun 2008, a las 18:15 , Uli Fouquet escribió:
> Philipp von Weitershausen wrote:
>
>> 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?
>
> The layer setup might currently not be as sophisticated as it would be
> desirable :-(
>
> When setting up a layer (only one is supported currently),

Then what's the point of the :Test-Layer: thing in the doctest? Just  
to indicate whether you use the (implicitly defined?) ZCML-based layer  
or not?

Also, I've not managed to make out the difference between the 'python'  
and the 'unit' setting for this parameter as described by the README.

> you can use the following parameters:
>
> - `zcml_config`: filesystem path to a ZCML config
>
>  Default: any `ftesting.zcml` in the package, that is registered.
>
>    Example::
>
>      import os
>      import z3c.testsetup
>      import my.package
>      test_suite = z3c.testsetup.register_all_tests(
>          'my.package',
>          zcml_config = os.path.join(
>              os.path.dirname(my.package.__file__), 'myftesting.zcml'))
>
>    will look for a file 'myftesting.zcml' in ``my.package``.

So this file becomes the 'functional' layer that you refer to  
from :Test-Layer: ?

> - `layer_name`: string
>
>  Registers the layer under the given name.
>
> - `layer`: ZCML layer object
>
>  This overrides any of the above options. This way you can define your
>  own layer like this::
>
>     from zope.app.testing.functional import ZCMLLayer
>     mylayer = ZCMLLayer(
>          os.path.join(os.path.dirname(__file__), 'ftesting.zcml'),
>          __name__,
>          'MyFunctionalLayer')
>
>   and call `register_all_tests` afterwards like this::
>
>      test_suite = z3c.testsetup.register_all_tests(
>          'my.package', layer = mylayer)
>
>
> More details about this can be found here:
>
> http://svn.zope.org/z3c.testsetup/trunk/src/z3c/testsetup/functionaldoctestsetup.txt
>
> I assume, you were aware of that possibilities,

I read the docs but I was much confused about all the assumptions the  
package makes. I think even a medium-sized application will quickly  
outgrow these assumptions. For instance, guessing that

   :Test-Layer: functional

*implicitly* loads ftesting.zcml didn't even cross my mind for a  
second, I thought it was somehow hooked up to FunctionalLayer.

> so there might be something missing. If so, please tell. I am very  
> open for proposals, how
> we can improve the usability of the package :-)

I think it could be improved in a very simple way: In doctests, you  
simply refer to the dotted name of the layer, e.g.:

   :Test-Layer: myapp.tests.IntegrationLayer

z3c.testsetup just finds the doctests, aggregates them, applies the  
layer they specify and returns them to the test runner. By default,  
there'd be a FunctionalLayer in grokproject (like there's already)  
which is being referred to from the minimal test in app.py.

WIth this, people can easily create new layers (just create another  
ZCML file, another ZCMLLayer definition in tests.py) and easily hook  
them up to their doctests.

What do you think?



More information about the Grok-dev mailing list