mercredi 10 avril 2019

Django test db connection not closed

I use Selenium to test that a language switcher on a Django site behaves properly. For internationalization I use Djangos build in capabilities.

The tests pass fine, but right after they finish, I get a psycopg2.OperationalError saying that there is one other session using the database. The tests aren't actually using the database, from what I can see only djangos session management is.

Setting SESSION_EXPIRE_AT_BROWSER_CLOSE to True doesn't help, even though I call driver.quit() in the tearDownCLass method of the test. Closing all connections through connections.close_all() changes nothing as well. select * from pg_stat_activity while running the test shows that there is indeed a idle connection open in the COMMIT stage while the test database is being dropped.

I can work around that issue by defining a DiscoverRunner that skips teardown_databases, but that's an ugly solution at best.

Aucun commentaire:

Enregistrer un commentaire