id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 33359 Don't close database connections after every TestCase Ran Benita nobody "Django's `TestCase` closes all DB connections at `tearDownClass`: https://github.com/django/django/blob/4.0/django/test/testcases.py#L1235-L1236 This makes it impossible to wrap a `TestCase` inside a larger DB transaction. This is something that an external project, pytest-django, would like to do. See here for more discussion: https://forum.djangoproject.com/t/why-does-django-close-db-connections-between-test-classes/10782 Besides the pytest-django angle (which Django itself should not really consider), DB connection setup can be somewhat heavy and so needlessly closing them adds overhead to the test run. We've tried to figure out why it was added. It seems to involve databases which perform SQL queries during *cursor* setup but it does not make much sense to me (see Django forum discussion). We've run the Django CI with these lines removed (including Oracle) and all of the tests pass. PR: https://github.com/django/django/pull/15156" Cleanup/optimization closed Testing framework dev Normal needsinfo Adam Johnson Unreviewed 1 0 0 0 0 0