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

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,

GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
Zope3-users mailing list

Reply via email to