I am running a set of fairly simple test cases using Flask, SQLAlchemy and PostgreSQL. Using the factory application, I defined the base unit test class as follows:
class BaseTestCase(unittest.TestCase): def setUp(self): self.app = create_app() self.app.config.from_object('app.config.test') self.api_base = '/api/v1' self.ctx = self.app.test_request_context() self.ctx.push() self.client = self.app.test_client() db.create_all() def tearDown(self): db.session.remove() db.drop_all(app=self.app) print db.engine.pool.status() if self.ctx is not None: self.ctx.pop()
Everything is going well for a few unit tests, so far:
OperationalError: (OperationalError) FATAL: remaining connection slots are reserved for non-replication superuser connections
It seems that there is only 1 connection in the pool (db.engine.pool.status () for each test shows: Pool size: 5 Connections in the pool: 1 Current overflow: -4 Current connections checked: 0), but somehow the application never shuts down. Obviously, for each test case, a new instance of the application is created that seems good in accordance with the documentation. If I move the application to the module level, it works fine.
Does anyone know why this is happening?
thanks
source share