zope.component.testlayer: Test Layers

zope.component.testlayer defines two things:

  • a LayerBase that makes it easier and saner to use zope.testing’s test layers.

  • a ZCMLFileLayer which lets you implement a layer that loads up some ZCML.

LayerBase

We check whether our LayerBase can be used to create layers of our own. We do this simply by subclassing:

Note that if we wanted to ensure that the methods of the superclass were called we have to use super(). In this case we actually wouldn’t need to, as these methods do nothing at all, but we just ensure that they are there in the first place.

Let’s instantiate our layer. We need to supply it with the package the layer is defined in:

Now we run some tests with this layer:

ZCMLFileLayer

We now want a layer that loads up some ZCML from a file. The default is ftesting.zcml, but here we’ll load a test testlayer.zcml. We can also choose to provide extra ZCML features that are used to conditionally control processing of certain directives (here we use “devmode”, a common condition for controlling development options like debugging output).

Since the ZCML sets up an adapter, we expect the tests to pass: