[Zope3-dev] layers can't be new style classes?

Jim Fulton jim at zope.com
Tue Oct 17 08:07:40 EDT 2006


Chris Withers wrote:
> Hi All,
> 
> It would appear that Philipp's article is somewhat misleading in that 
> layers can't be new style classes...
> 
> class MyLayer(object):
> 
>    def setUp(self): pass
> 
>    def tearDown(self): pass
> 
> ..results in the following when used as a layer:
> 
> AttributeError: type object 'object' has no attribute 'setUp'
> 
> Is this a bug in Philipp's article or in the testrunner?

In Philipp's article.

Note that test layers don't have to be classes.  Classes
with class methods just happen to be a (seductively) convenient
implementation.  For example, ZCMLLayer defined in zope.app.testing.functional
is not a class, in the sense that Layer instances are not classes.

A layer is simply an object that has __module__, __name__, and __bases__
attributes and that has setUp and tearDown methods.  That's it.  You
can achieve that any way you want.  I regret the use of the __bases__
attribute.  It would have been better if I had left it up to layer
implementations to call base layers, rather than having the test runner call
them automatically.  It was a bad automation tradeoff.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list