Fix database connection leak in tests

Without this, each flask app created in tests will hold
one database connection until all tests are finished. This may result
in test failure if database limits number of concurrent connections.