Skip to content

Commit

Permalink
Close all sessions to prevent tests hanging. Cleanup logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkrimer committed Nov 19, 2015
1 parent 968caa3 commit 7b4e131
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions common/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import json
import yaml
import logging
import importlib
import http.client

from os import path
from operator import itemgetter
from flask.json import dumps
from flask.logging import create_logger
from flask.testing import FlaskClient
from flask.wrappers import Response
from contextlib import wraps
Expand Down Expand Up @@ -87,7 +87,7 @@ def setUp(self):
assert hasattr(self, 'app'), 'Please provide a reference to the Flask app'
assert hasattr(self, 'db'), 'Please provide a reference to the Flask SQLAlchemy object'

self.logger = create_logger(self.app)
self.logger = logging.getLogger(self.__class__.__name__)

# Configure app for testing
self.app.testing = True
Expand Down Expand Up @@ -160,10 +160,9 @@ def tearDown(self):
up the SQLAlchemy session.
"""

# Need to manually rollback the transaction because, of course, Flask does not do this
# automatically (on error or any other reason). Flask manages the session but has no opinion on
# transaction handling.
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.0.9',
version='0.1.1',
author='Unascribed',
author_email='[email protected]',
description='Code intended to be used across Polymath Ventures repositories.',
Expand Down

0 comments on commit 7b4e131

Please sign in to comment.