#20392: Rearrange transactional behavior in django.test.TestCase: savepoints
around
tests
-------------------------------------+-------------------------------------
Reporter: xelnor | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: test atomic | Triage Stage: Accepted
savepoint | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Comment (by xelnor):
The `reset_connections_per_test` attribute is here to avoid duplicating
the logic in `TransactionTestCase._post_teardown`.
The current behavior (see
https://github.com/django/django/blob/master/django/test/testcases.py#L516)
is to close all database connections after `self.tearDown`.
I wanted to be able to distinguish between `TransactionTestCase`, where
this connection closure is required for database reset, and `TestCase`,
where it should be avoided to gain the features discussed above.
Put another way, the current behaviour is:
- `TransactionTestCase` recreates the database and loads fixtures before
each `test_foo`; closes the connection after each `test_foo`.
- `TestCase` creates the database once, loads `TestCase`-specific fixtures
before each `test_foo`; rolls back the transaction and closes the
connection after each `test_foo`.
The goal is:
- No change to `TransactionTestCase`
- `TestCase` creates the database once, begins a transaction at
`setUpClass` where it loads `TestCase`-specific fixtures, makes a
savepoint before each `test_foo`, rolls back to savepoint after each
`test_foo`, rolls back the transaction then closes connections in
`tearDownClass`.
I'll try to upgrade the patch with more comments, and move the "load
fixtures" code to `setUpClass`.
This discussion should probably move to django-developers@, what do you
think?
--
Ticket URL: <https://code.djangoproject.com/ticket/20392#comment:3>
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.