#20316 closed Cleanup/optimization (fixed)
TestCase will let code rollback and commit without warning
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | testcase transactions |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The docs for TransactionTestCase say TestCase
"prevents the code under test from issuing any commit or rollback operations on the database". Code running in a TestCase
that uses commit
or rollback
will still appear to work. Of course, those functions don't do anything, they have been replaced by a nop
function that silently does nothing -- see here.
The 'silently' part does not help a user that is using TestCase
but should be using TransactionTestCase
.
Change History (7)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Component: | Testing framework → Documentation |
---|---|
Easy pickings: | set |
Keywords: | testcase transactions added |
Needs documentation: | set |
Type: | Uncategorized → Cleanup/optimization |
Version: | 1.4 → master |
Unfortunately first and second options are no-go since there's no reliable way to differentiate implicit from explicit commit
and rollback
calls.
i.e. You'd like explicit transaction.commit
call to raise an exception or a warning but not the implicit calls from Model().save()
.
It would also be highly backward incompatible.
Third option seems reasonable, a documentation patch is welcome!
comment:3 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 12 years ago
I've changed the docs, basically restating what the ticket author has already said.
patch at: https://github.com/lolek09/django/commit/2df87c45496bf7a9e2da109ffee20d50b40af042.patch
graphic diff: https://github.com/lolek09/django/commit/2df87c45496bf7a9e2da109ffee20d50b40af042
comment:5 by , 11 years ago
Has patch: | set |
---|
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In a perfect world, I would like to see at least one of the following happen:
nop
raise an exception warning the user that they should be usingTransactionTestCase
TransactionTestCase
updated to not use the word 'prevents', and mention something about how functions likecommit
androllback
are essentially callable nops when used in aTestCase
.