[Grok-dev] z3c.testsetup released

Uli Fouquet uli at gnufix.de
Fri Feb 15 18:52:01 EST 2008


Hi there,

I finally managed to release the z3c.testsetup package. It's available
from cheeseshop and the svn.zope.org repository.

The current version is ALPHA-ware, which is worse than 'beware'. Do not
trust it, do not rely on it! Don't expect the API to stay! Brave souls,
that check it out although, might consider to share their experiences
with me, so that I can improve the stuff and fix any shortcomings.

Currently, no valuable ZCML-config comes with the defaults, so you have
to define your own (or take another one that suits your needs) if you
need for instance special principals during your functional doctests. 

This release might build the base for the upcoming grok testing support.
The grok version will come with a more verbose ftesting.zcml, which
should serve at least some normal grokprojects out-of-the-box.

Some documentation can be found on the cheeseshop:

	http://pypi.python.org/pypi/z3c.testsetup

The .txt files are at

        http://svn.zope.org/z3c.testsetup/trunk/src/z3c/testsetup

might be helpful as well.

Some notes for the impatient:

Setting up a project with z3c.testsetup:
========================================

This is done in two steps:

1) Write a setup file
---------------------

Given, your project is organized like a usual grokproject or otherwise
buildoutified, add 'z3c.testsetup' to the required packages in your
setup.py. Run buildout to fetch the package.

Then, edit a file in your src/<projectname> directory, that will be
found by the testrunner. Normally this includes filenames like
'tests.py' or 'ftests.py'.

In this file, write something like::

   import z3c.testsetup
   test_suite = z3c.testsetup.register_all_tests('<mypackagename>')

That's it for the setup. This is the whole file.

If you have a special 'ftesting.zcml' you want to have registered, use::

   import z3c.testsetup
   test_suite = z3c.testsetup.register_all_tests(
       '<mypackagename>', 
       zcml_config = '<path_to_zcml_file>',
       layer_name  = 'MyFunctionalLayer')

Grokprojects already provide a testing module, that defines a complete
ZCML-Layer with principals etc. It can be activated like this with
z3c.testsetup::

   import z3c.testsetup
   from <myprojname>.testing import FunctionalLayer
   test_suite = z3c.testsetup.register_all_tests(
       '<myprojname>', layer = FunctionalLayer)

2) Mark your test files/modules
-------------------------------

Modify the modules and doctest files you want to include as follows:

  - doctestfiles must have .txt or .rst filename extension and must
    provide a marker in the text that reads like this::

      :Test-Layer: functional

    for functional doctests, or::

      :Test-Layer: unit

    for unit doctests.

  - 'normal' Python modules (now supported) must provide a module
    docstring, that reads::

      :Test-Layer: python

    Normal Python modules are considered those, that define TestCases 
    (contrary to examples, as doctests do). If you do doctests inside 
    Python modules (for example in docstrings of classes and functions 
    therein), add one of the *doctest* markers 
    in the module docstring and call::

      test_suite = z3c.testsetup.register_all_tests(
         '<mypackagename>',
         extensions=['.txt', '.rst', '.py'])

    in your setup file.

If you now run a testrunner (bin/test for example), the marked testfiles
should be found and the tests be executed.

There is a lot of documentation in the package itself, which can tell
you how to modify standard test setups.

Kind regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20080216/815df547/attachment.bin


More information about the Grok-dev mailing list