[ZODB-Dev] DemoStorage stacking in zope.testing layers

Martin Aspeli optilude+lists at gmail.com
Mon Apr 5 10:36:49 EDT 2010


Hi,

I'm trying to do something like the following:

  - A test layer "EmptyZODB" sets up an empty ZODB using DemoStorage and 
exposes the DB object to other layers and tests.

  - A test layer "Foo" has "EmptyZODB" as a base. It opens a connection 
during layer setup, makes some changes, commits those, and closes the 
connection.

  - A test layer "Bar" has "Foo" as a base. It pushes a new DemoStorage 
on top of the one that was modified by "Foo", opens a new connection, 
makes changes, commits those, and closes the connection.

  - On layer tear-down, "Bar" pops the demo storage, leaving the 
pristine fixture from "Foo".

The problem with this scenario is that the database that was created by 
"EmptyZODB" and then modified by "Foo" is by necessity already "active" 
(even if it has no open connections). From my reading of the 
docs/interfaces, it's not possible to "swap out" a storage of a DB 
object, i.e. the storage is only settable in the constructor.

What is the correct way to use DemoStorage stacking in test layers? 
Should "Bar" create a new DB object of its own and expose that to the 
tests that need it? Or is there some way to keep the same "DB" object 
(which would make the tests easier to write in this case) and simply 
tell it to use the top of the stack at all times?

Martin



More information about the ZODB-Dev mailing list