Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#20316 closed Cleanup/optimization (fixed)

TestCase will let code rollback and commit without warning

Reported by: uberj@… Owned by: nobody
Component: Documentation Version: master
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


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 Changed 4 years ago by uberj@…

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

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 using TransactionTestCase
  • A print statement warning the user
  • The docs on TransactionTestCase updated to not use the word 'prevents', and mention something about how functions like commit and rollback are essentially callable nops when used in a TestCase.

comment:2 Changed 4 years ago by Simon Charette

Component: Testing frameworkDocumentation
Easy pickings: set
Keywords: testcase transactions added
Needs documentation: set
Type: UncategorizedCleanup/optimization
Version: 1.4master

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 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:4 Changed 3 years ago by anonymous

comment:5 Changed 3 years ago by Tim Graham

Has patch: set

comment:6 Changed 3 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In dffdca1109a2111f104f2419d081c0f971537fec:

Fixed #20316 - Clarified transaction behavior of TestCase.

Thanks uberj@ for the report and lolek09 for the patch.

comment:7 Changed 3 years ago by Tim Graham <timograham@…>

In cd15a51c3eb2918107814e7c42533ebef982a431:

[1.5.x] Fixed #20316 - Clarified transaction behavior of TestCase.

Thanks uberj@ for the report and lolek09 for the patch.

Backport of dffdca1109 from master

Note: See TracTickets for help on using tickets.
Back to Top