[Grok-dev] Easier test setup with new grok.testing

Uli Fouquet uli at gnufix.de
Sun Feb 10 10:19:15 EST 2008

Hi there,

I created an external branch (Sandbox/ulif/z3c-testsetup) in the
repository for preparation of a z3c.testsetup package, that should
provide the functionality for easier test setups as discussed earlier on
this list.

The work is nearly finished, but I would like to get your input for the
usability of the whole thing before releasing it.

Christian Theune wrote:
> Uli Fouquet schrieb:
> >        import unittest
> >        import grok
> >        import cave # The package that contains the doctest files
> > 
> >        def test_suite():
> >            setup = grok.testing.UnitTestSetup(cave)
> >            return setup.getTestSuite()
> > 
> >        if __name__ == '__main__':
> >            unittest.main(default='test_suite')

> I have the feeling that we could easily reduce this to without major hassle:
> import grok.testing
> test_suite = grok.grok_tests('cave')

> I'm a bit worried that this code is already on the trunk and not on a 
> branch. IMHO it needs a bit more work on the usability side and should 
> be on a branch for now.

Current State

With the current branch (not 'trunk', this time ;-) it is possible to
register tests like this::

   import z3c.testsetup
   test_suite = z3c.testsetup.register_all_tests('cave')

You can also do::

   import z3c.testsetup
   import cave
   test_suite = z3c.testsetup.register_all_tests(cave)

This registers all tests (unit doctests, functional doctests and
'normal' Python unittests) that provide a special markup string:

  - unit doctest files must contain a string::

	:Test-Layer: unit

  - functional doctest files must contain a string::

        :Test-Layer: functional

  - Python modules with tests must provide a module docstring that 
    contains a line::

        :Test-Layer: python

Doctest files must have .rst or .txt filename extension by default.

'Python tests' must be regular Python modules that should contain
definitions of `unittest.TestCase` classes.

The `register_all_tests` function allows a lot of keyord parameters to
customize finding and setting up of tests, modifying the default

The complete syntax for the function is currently::


whereas f... and u... options handle functional and unit doctests
repectively and override any 'global' parameter with the same name. For


will look in .bar-files for functional doctests and in '.baz' files for
unit doctests. .foo-files will be skipped, while

                     extensions=['.foo', '.bar'])

will look in all .bar and .foo files for unitdoctests and functional

Beside the package parameter everything is optional. Extensive
documentation to the defaults and everything else is available at::


Any feedback, how the usability could be improved would be very welcome.

Kind regards,


More information about the Grok-dev mailing list