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

Christian Theune ct at gocept.com
Wed Jan 30 02:40:47 EST 2008



Uli Fouquet schrieb:
> Hi there,
> 
> I just merged my testsetup extension into the branch, because I am lazy,
> my memory is like a sieve and I didn't want to remember all the dirty
> details of test setups any more when starting a new grok project. Hope,
> nothing will break.

With "the branch" you mean "the trunk", right? At least that's where 
your links go.

> To make use of this extension in your grok project, you have to perform
> three steps:
> 
> 1) Mark your doctests with either::
> 
>      :Test-Layer: functional
> 
>    or::
> 
>      :Test-Layer: unit
> 
>    Choose the first term, if your file contains functional tests, the 
>    latter term, if it contains unit tests.

Nice.

> 2) Setup testing.
> 
>    Create a Python file whose name starts with 'tests' in your app. For 
>    example `tests.py`, `tests_myapp.py` or `tests_setup.py`.
> 
>    Populate this file with your tests' setup.
> 
>    This normally is a bit complicated and you have to remember several 
>    things/commands/options etc. The shortest setup you can use now looks
>    like this::
> 
>        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')

Minor aside: Why do people keep adding the `main` feature? I haven't 
used it myself in a long time and my guess is that you actually won't be 
able to use it too conveniently because of eggs. (You might be able to 
use it when using a custom built interpreter script that you start this 
file with. OTOH if you want to run tests selectively the test runner has 
much more fine grained options.)

>    This will search your ``cave`` package (including subdirectories) 
>    for any .rst or .txt files, that contain the testlayer marker string 
>    as mentioned above and will register the files as doctests.
> 
>    You want to setup unittests and functional tests once in a row? Here 
>    we go::
> 
>        import unittest
>        import grok
>        import cave # The package that contains the doctest files
> 
>        def test_suite():
>            suite = unittest.TestSuite()
>            suite.addTest( # Add all unittests from `cave`
>                grok.testing.UnitTestSetup(cave).getTestSuite())
>            suite.addTest( # Add all functional tests from `cave`
>                grok.testing.FunctionalTestSetup(cave).getTestSuite())
>            return suite
> 
>        if __name__ == '__main__':
>            unittest.main(default='test_suite')

Hmm. Interesting. In my oppinion I shouldn't have to do anything else 
for functional or unit tests, so this should stay:

import grok
test_suite = grok.grok_tests('cave')

> There is about one zillion of possibilities to change the default
> behaviour of `UnitTestSetup` and `FunctionalTestSetup`. You can change
> the filename extensions to look for, the `globs`, the tearDown-methods,
> the marker strings and many, many more.
> 
> You can (and should, if you use it) read more about it in the test files
> of this extension:
> 
> 	http://svn.zope.org/grok/trunk/src/grok/tests/testsetup/

> Documentation on the grok site will follow in the next days if no
> serious objections or changes should happen.

I'm sorry that I'm stepping in only every now and then, I'm trying to 
become a bit more regular again. Hopefully I didn't miss any important 
discussion when throwing things in here now.

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.

Christian

-- 
gocept gmbh & co. kg - forsterstrasse 29 - 06112 halle (saale) - germany
www.gocept.com - ct at gocept.com - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development


More information about the Grok-dev mailing list