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 

  - 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?


For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to