python - Flask unit tests with SQLAlchemy and PostgreSQL exhausts db connections -
i'm running suite of straightforward test cases using flask, sqlalchemy, , postgresql. using application factory, i've defined base unit test class so:
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 not none: self.ctx.pop()
all goes few unit tests, until:
operationalerror: (operationalerror) fatal: remaining connection slots reserved non-replication superuser connections
it seems there 1 connection in pool (db.engine.pool.status() each test shows: pool size: 5 connections in pool: 1 current overflow: -4 current checked out connections: 0), somehow app never disconnects. new app instance created each test case, seems fine according documentation. if move app creation module level works fine.
does know why happening?
thanks
add db.get_engine(self.app).dispose()
after db.drop_all()
Comments
Post a Comment