#33359: Don't close database connections after every TestCase
------------------------------------------------+------------------------
Reporter: Ran Benita | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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
--
Ticket URL: <https://code.djangoproject.com/ticket/33359>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.2eede9cb601dc54e9ca73a76c4079940%40djangoproject.com.