For those of you who say they don’t like doctests because they don’t
give you isolation between tests. Here’s an example of an integration
doctest for Plone that gives you exactly that:
from Testing import ZopeTestCase as ztc
from Products.PloneTestCase import PloneTestCase as ptc
from Products.PloneTestCase.layer import PloneSite
ZOPE_DEPS = ['MyZopeProductDependecy']
PLONE_DEPS = ['MyPloneProduct',
'MyPloneDependency']
for x in ZOPE_DEPS + PLONE_DEPS:
ztc.installProduct(x)
ptc.setupPloneSite(products=PLONE_DEPS)
class MyTest:
def test_one():
r"""
Check if one and one is two:
>>> 1 + 1
2
"""
def test_two():
r"""
Check if one minus one is zero:
>>> 1 - 1
0
"""
def test_suite():
suite = ztc.ZopeDocTestSuite(test_class=ptc.PloneTestCase)
suite.layer = PloneSite
return suite
Look at G. Writing Tests in the (somewhat out of date) The Zope 3
Developer’s Book for more inspiration.
Don’t do traditional-style unit tests, they’re ugly. Is this a
matter of test, err taste? I don’t think so.
Daniel Nouri: *Isolated* doctests for Plone
Originally from Planet Plone
http://plonewars.com/2007/03/23/daniel-nouri-isolated-doctests-for-plone/