[Zope3-Users] Re: testrunner layers example and classmethods

Paul Winkler pw_lists at slinkp.com
Fri Jul 28 16:50:28 EDT 2006

Finally following up... Thanks for the clarification.

For anybody else puzzling over how to use layers, there are
a couple details that weren't obvious to me from the
docs. I wrote them up here:

and a front page at http://zopewiki.org/TestLayers


On Mon, Jul 10, 2006 at 09:51:03PM +0200, Philipp von Weitershausen wrote:
> Paul Winkler wrote:
> > I have a need to have a batch of tests that do some expensive
> > setup once for the whole batch.  AFAICT this is what layers are for.
> Indeed.
> > One question though... Why do the examples in
> > zope/testing/testrunner-ex/samplelayers.py have setUp() and tearDown()
> > as classmethods?
> Because the test runner expects layers to be objects with setUp() and
> tearDown() "methods". So, if you want to pass a class without
> instantiating it first, you need to make these class methods so that
> they don't expect 'self' as the first argument.
> > Is it just an implementation detail of those tests, or something
> > I should be aware of when creating my own layers?
> Just pass in any object that has 'setUp' and 'tearDown' callables as
> attributes :).

Well, no, it also needs __bases__ and __name__ attributes, as I
discovered. So a vanilla class instance won't work unless you provide
those at least.

I don't know if there are other constraints with using instances,
I didn't investigate further.

It also cannot be a new-style class, as the test runner expects *all*
base classes to have a setUp() method, and object does not.

An old-style class with classmethods is really the most convenient


Paul Winkler

More information about the Zope3-users mailing list