[Zope3-Users] How to close a ZODB connection and reopen it for testing?

Hermann Himmelbauer dusty at qwer.tk
Mon Nov 19 18:17:18 EST 2007


Hi,
I am currently writing a doctest for one of my persistent classes. It's 
purpose is to check, if object modifications, e.g. through methods, are 
really persistent, however, my objects are magically remembered, therefore I 
cannot properly test them.

My doctest looks like this:

 >>> from ZODB import FileStorage, DB
 >>> storage = FileStorage.FileStorage('tests/tmp/test.fs')
 >>> db = DB(storage)
 >>> conn = db.open()
 >>> dbroot = conn.root()
 >>> x = myClass()
 >>> dbroot['x'] = x

Now I can do some modifications of my object, call some methods which modify 
the object and call transaction.commit().

Next I want to somehow close the database, reopen it, read my object and check 
if my modifications were really stored, e.g.:

 >>> conn.close()
 >>> db.close()
 >>> conn = db.open()
 >>> dbroot = conn.root()
 >>> y = dbroot['x']

But unfortunately, the following applies:

 >>> x is y
 True

This is bad, as it means that Python/ZODB magically remembered my object and 
did not reread it from the database. Therefore I cannot correctly check 
persistence issues.

What is the suggested solution to this?

Best Regards,
Hermann

-- 
x1 at aon.at
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7


More information about the Zope3-users mailing list