Updates clear_db() to unregister models and close session.
fixes bug 1080988 This change fixes the bug by ensuring the metadata and session objects are properly cleaned up by clear_db(). Using the proper calls reduces the memory required by unit tests. Change-Id: I1d1802b642eff83b7f96211608195afaf68e855a
This commit is contained in:
parent
cf8b92af9a
commit
92ee709521
@ -85,13 +85,15 @@ def configure_db(options):
|
|||||||
|
|
||||||
|
|
||||||
def clear_db(base=BASE):
|
def clear_db(base=BASE):
|
||||||
global _ENGINE
|
global _ENGINE, _MAKER
|
||||||
assert _ENGINE
|
assert _ENGINE
|
||||||
for table in reversed(base.metadata.sorted_tables):
|
|
||||||
try:
|
unregister_models(base)
|
||||||
_ENGINE.execute(table.delete())
|
if _MAKER:
|
||||||
except Exception as e:
|
_MAKER.close_all()
|
||||||
LOG.info("Unable to delete table. %s.", e)
|
_MAKER = None
|
||||||
|
_ENGINE.dispose()
|
||||||
|
_ENGINE = None
|
||||||
|
|
||||||
|
|
||||||
def get_session(autocommit=True, expire_on_commit=False):
|
def get_session(autocommit=True, expire_on_commit=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user