[Python-Dev] setUpClass and setUpModule in unittest
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Thu Feb 11 17:33:42 CET 2010
On 04:18 pm, tseaver at palladion.com wrote:
>
>Just as a point of reference: zope.testing[1] has a "layer" feature
>which is used to support this usecase: a layer is a class namedd as an
>attribute of a testcase, e.g.:
>
> class FunctionalLayer:
> @classmethod
> def setUp(klass):
> """ Do some expesnive shared setup.
> """
> @classmethod
> def tearDown(klass):
> """ Undo the expensive setup.
> """
>
> class MyTest(unittest.TestCase):
> layer = FunctionalLayer
>
>The zope.testing testrunner groups testcase classes together by layer:
>each layer's setUp is called, then the testcases for that layer are
>run,
>then the layer's tearDown is called.
>
>Other features:
>
>- - Layer classes can define per-testcase-method 'testSetUp' and
>'testTearDown' methods.
>
>- - Layers can be composed via inheritance, and don't need to call base
> layers' methods directly: the testrunner does that for them.
>
>These features has been in heavy use for about 3 1/2 years with a lot
>of
>success.
>
>
>[1] http://pypi.python.org/pypi/zope.testing/
On the other hand:
http://code.mumak.net/2009/09/layers-are-terrible.html
I've never used layers myself, so I won't personally weigh in for or
against.
Jean-Paul
More information about the Python-Dev
mailing list