Skip to content

Commit

Permalink
Need to flush() in a try/finally block since it can fail.
Browse files Browse the repository at this point in the history
If it fails (which is the whole point of having it there) we still need to cleanup after and propagate the exception.
  • Loading branch information
gkrimer committed Mar 25, 2016
1 parent 180f2d4 commit acd5a83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions common/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ def tearDown(self):
# represented in SQL but are perfectly fine in Python. SQLAlchemy has its own heuristics governing when to
# flush, such as before issuing any queries, but there is no guarantee it happens after every test so we do
# it here. Committing the session also forces a flush but is a heavier operation.
self.db.session.flush()
self.db.session.rollback()

# Tearing down all sessions seems drastic, but simply rolling back the current transaction does not
# terminate all database connections, which can cause the tests to hang.
self.db.session.close_all()
self.context.pop()
try:
self.db.session.flush()
finally:
self.db.session.rollback()

# Tearing down all sessions seems drastic, but simply rolling back the current transaction does not
# terminate all database connections, which can cause the tests to hang.
self.db.session.close_all()
self.context.pop()

def assertEntitiesContain(self, actual_entities, expected_entities):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='common',
version='0.1.3',
version='0.1.4',
author='Unascribed',
author_email='[email protected]',
description='Code intended to be used across Polymath Ventures repositories.',
Expand Down

0 comments on commit acd5a83

Please sign in to comment.