Looking under the hood? Interested in a job? Send a mail....


infrae.testing defines sanes tests layers for testing in Zope 2, to use in conjunction with zope.testing.



It defines:

If you use the ZCMLLayer or Zope2Layer, you have two different callbacks registry you can use:

Those callbacks registry have an add method that can be used in order to register a new cleanup function:

from infrae.testing import testCleanUp




A example to test a package called corp.testpackage. The package as a ftesting.zcml file which should mainly load its own configure.zcml:

import unittest

from infrae.testing import ZCMLLayer
import corp.testpackage

layer = ZCMLLayer(corp.testpackage)

class MyTestCase(unittest.TestCase):

    layer = layer

The layer provides you a grok() method that can be used to grok a module in your test later on.


Now our corp.testpackage is a Zope 2 extension providing some content. We want to test it installed:

import unittest

from infrae.testing import ZCMLLayer
import corp.testpackage

class CorpLayer(Zope2Layer):
    """Add some installation tasks to the Zope2Layer.
   default_products = Zope2Layer.default_products + ['CMFCore']
   default_packages = Zope2Layer.default_packages + ['corp.testpackage']
   default_users = Zope2Layer.default_users + {'corp_user': 'CorpRole'}

   def _install_application(self, app):
      factory = app.manage_addProduct['corp.testpackage']

layer = CorpLayer(corp.testpackage)

class MyTestCase(unittest.TestCase):

    layer = layer

    def setUp(self):
        self.root = self.layer.get_application()

Of course your ZCML must include the ZCML of your package dependencies. As well we don't recommend to add Five in the layer as a default_products, it goes crazy (but include it in your ZCML !).

The layer provides you the following useful methods:

Log as a the given username.
Return the root of the database, not wrapped in a request.
Return the root of the database, wrapped in a request.


The code is available through a Mercurial repository at: https://hg.infrae.com/infrae.testing

Available releases

Release version Release date Release files
infrae.testing 1.3 2012 9 3 16:34:46 infrae.testing-1.3.tar.gz
infrae.testing 1.2 2011 11 7 13:55:19 infrae.testing-1.2.tar.gz
infrae.testing 1.1 2010 10 7 11:09:00 infrae.testing-1.1.tar.gz
infrae.testing 1.0 2010 7 15 17:41:25 infrae.testing-1.0.tar.gz

License: New BSD