Skip to content Skip to sidebar Skip to footer

Sqlalchemy Force All Connections To Close Mysql

We use sqlalchemy in some complicated unit tests. At the end of each test, we tear down the database entirely using drop_all. Now and then, someone forgets to close a session embed

Solution 1:

In flask, this should do the trick:

@app.teardown_appcontext
def teardown_db(exception):
    db.session.commit()
    db.session.close()

Post a Comment for "Sqlalchemy Force All Connections To Close Mysql"