Chris Withers wrote:
Jim Fulton wrote:
Am I right in assuming that there aren't any good narrative docs for test layers?

This is obviously in the eye of the beholder.  I'm sure the people
who created narratives tried to do a good job. Perhaps you can do better.

I may be missing some then... which narratives are you thinking of?

You cited 3 in your note.


Now, related to this, say I have content objects X and Y, which are expensive to set up. I have LayerX which sets up a sample content object X, and LayerY which does the same for content object Y. This is fine for tests which need one or other content type, but how do I write tests which need both?

You create a layer that extends both.

How so?

You create a layer whose __bases__ include LayerX and
LayerY.  If you're layers happen to be implemented
as classic classes, you then could use subclassing.

Here's a sample of why I'm struggling:

class ZODB:

   def setUp(cls):
       ... open zodb connection
       ... begin transaction

   def tearDown(cls):
       ... abort transaction
       ... close connection

class LayerX(ZODB):

   def setUp(cls):
       cls.savepoint = transaction.savepoint()
       ... create X instance

   def tearDown(cls):

class LayerY(ZODB):

   def setUp(cls):
       cls.savepoint = transaction.savepoint()
       ... create Y instance

   def tearDown(cls):

class MyLayer(LayerX,LayerY): pass

class MyTests(TestCase):

   layer = '.MyLayer'

   def setUp(self):
       self.savepoint = transaction.savepoint()

   def tearDown(self):

   def test_1(self):

Basically, will the above work or will the savepoints become a horrible jumbled mess and I end up with several ZODB connections as well?

That's a good question. Looking at the code on the zope.testing trunk,
it looks like this should work.

PS: can I use '.MyLayer' as a layer, or do I always need to put the full dotted path in?

You have to use a full dotted path.  You can also use the
Layer object itself.


Jim Fulton           mailto:[EMAIL PROTECTED]       Python Powered!
CTO                  (540) 361-1714  
Zope Corporation
Zope3-dev mailing list

Reply via email to