diff options
| author | Tim Graham <timograham@gmail.com> | 2013-05-23 10:57:44 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-05-23 11:12:33 -0400 |
| commit | cd15a51c3eb2918107814e7c42533ebef982a431 (patch) | |
| tree | 5cf43a54fff1a5a68db46d4822f4e80cb1292823 /docs/topics | |
| parent | 9ed2121eca0d4543dd665d7c5a3015beaee28eb4 (diff) | |
[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
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/testing/overview.txt | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/docs/topics/testing/overview.txt b/docs/topics/testing/overview.txt index 043823f965..58694a6e3f 100644 --- a/docs/topics/testing/overview.txt +++ b/docs/topics/testing/overview.txt @@ -910,14 +910,23 @@ to test the effects of commit and rollback: * A ``TestCase``, on the other hand, does not truncate tables after a test. Instead, it encloses the test code in a database transaction that is rolled - back at the end of the test. It also prevents the code under test from - issuing any commit or rollback operations on the database, to ensure that the - rollback at the end of the test restores the database to its initial state. + back at the end of the test. Both explicit commits like + ``transaction.commit()`` and implicit ones that may be caused by + ``Model.save()`` are replaced with a ``nop`` operation. This guarantees that + the rollback at the end of the test restores the database to its initial + state. When running on a database that does not support rollback (e.g. MySQL with the MyISAM storage engine), ``TestCase`` falls back to initializing the database by truncating tables and reloading initial data. +.. warning:: + + While ``commit`` and ``rollback`` operations still *appear* to work when + used in ``TestCase``, no actual commit or rollback will be performed by the + database. This can cause your tests to pass or fail unexpectedly. Always + use ``TransactionalTestCase`` when testing transactional behavior. + .. note:: .. versionchanged:: 1.5 |
