nti.testing.zodb#
Support for testing of ZODB applications.
New in version 3.0.0.
- class nti.testing.zodb.ZODBLayer[source]#
Bases:
ZopeComponentLayer
Test layer that creates a ZODB database using
ZODB.DemoStorage.DemoStorage
and registers it as the no-nameZODB.interfaces.IDatabase
in the global component registry. It is also available in thedb
attribute of this object.- db = None#
The DB that was created.
- classmethod testSetUp()[source]#
Calls
sharedCleanup()
for every test.
- classmethod testTearDown()[source]#
Calls
sharedCleanup()
for every test.
- class nti.testing.zodb.mock_db_trans(db=None)[source]#
Bases:
object
A context manager that begins and commits a database transaction.
This class may be subclassed; there are some extension points to allow customization.
This class is not designed for concurrency.
Entering this context manager begins a transaction using the thread-local global transaction manager and returns a connection open to the database given in the db parameter. Exiting this context manager commits the transaction (or aborts it if it is doomed).
It is an error to enter this context manager with a transaction already in progress. The global transaction may be committed or aborted before exiting this transaction, but no new transaction may be opened. During execution of the body, the transaction manager is in explicit mode; it is an error if this is changed during the body.
- Parameters:
db – The
ZODB.DB
to open. If none is given, then theZODBLayer.db
will be used.
- conn = None#
The connection that was opened. Valid after entering and before exiting.
- exc_file = None#
The file to which unexpected exceptions that cannot be raised are printed. If
None
, exceptions will be written tosys.stderr
- nti.testing.zodb.reset_db_caches(db=None, collect=False)[source]#
Minimize the caches of all connections found in the db.
If the db is not given, then the one from the
ZODBLayer
is used.On PyPy, or if collect is true, this will invoke
gc.collect()
to help remove any weak references to objects that were ejected from the cache.