[Checkins]
SVN: z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt
Add tests for unit doctest layers.
Uli Fouquet
uli at gnufix.de
Mon Jul 28 06:52:34 EDT 2008
Log message for revision 88857:
Add tests for unit doctest layers.
Changed:
A z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt
-=-
Added: z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt
===================================================================
--- z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt (rev 0)
+++ z3c.testsetup/trunk/src/z3c/testsetup/layerrunner.txt 2008-07-28 10:52:33 UTC (rev 88857)
@@ -0,0 +1,76 @@
+========================
+z3c.testsetup and layers
+========================
+
+Here we discuss complete testsetups that involve test layers. Test
+layers are a method to group several tests or test suites in groups.
+
+Layers are a method to do time-consuming setups like initializing
+databases or whatever only once for a whole bunch of tests. Such you
+can save time and make your testing setup less error-prone.
+
+See `layered_cave/layer.py` for examples of working layers. We will
+use the layers defined there in the following examples.
+
+Simple unit doctests with layers
+--------------------------------
+
+Using z3c.testsetup, we can define quite complex testsetups with only
+two lines of code::
+
+ >>> import os
+ >>> cavepath = os.path.join(os.path.dirname(__file__), 'tests',
+ ... 'layered_cave')
+ >>> setupfile = os.path.join(cavepath, 'layeredsetup01.py')
+ >>> print open(setupfile).read()
+ from z3c.testsetup import register_all_tests
+ test_suite = register_all_tests('z3c.testsetup.tests.layered_cave')
+
+This means, that we want to register all tests (doctests and 'normal'
+python tests) from the ``layered_cave`` package, whose name we passed in
+dotted name notation as a string. This is enough information for a
+testrunner.
+
+In one of the test files we declared, that a layer should be used::
+
+ >>> testfile = os.path.join(cavepath, 'adoctest.txt')
+ >>> print open(testfile, 'r').read()
+ This is a doctest
+ =================
+ <BLANKLINE>
+ This doctest will be applied to a layer.
+ <BLANKLINE>
+ :Test-Layer: unit
+ :Test-Layerdef: z3c.testsetup.tests.layered_cave.layer.UnitLayer1
+ ...
+
+The line saying `:Test-Layerdef:` tells, that we want the layer
+denoted by the trailing dotted name should be applied to the tests of
+the file. It is vital that the denoted object really exist. The format
+of the layer declaration is::
+
+ :Test-Layerdef: <dotted.name.of.layer.definition>
+
+where the marker string can be written in upper or lower or mixed
+case. Doing so, the testrunner will apply the declared layer to our
+tests::
+
+ >>> import sys
+ >>> defaults = [
+ ... '--path', cavepath,
+ ... '--tests-pattern', '^layeredsetup01$',
+ ... ]
+ >>> sys.argv = 'test '.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ Running z3c.testsetup.tests.layered_cave.layer.UnitLayer1 tests:
+ Set up z3c...layered_cave.layer.UnitLayer1 in 0.000 seconds.
+ Running testSetUp of UnitLayer1
+ Running testTearDown of UnitLayer1
+ Ran 1 tests with 0 failures and 0 errors in ... seconds.
+ Tearing down left over layers:
+ Tear down z3c...layered_cave.layer.UnitLayer1 in 0.000 seconds.
+ False
+
+As we can see, the layer `UnitLayer1` was executed here.
+
More information about the Checkins
mailing list