Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

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

Backport of dffdca1 from master
  • Loading branch information...
commit cd15a51c3eb2918107814e7c42533ebef982a431 1 parent 9ed2121
Tim Graham authored May 23, 2013

Showing 1 changed file with 12 additions and 3 deletions. Show diff stats Hide diff stats

  1. 15  docs/topics/testing/overview.txt
15  docs/topics/testing/overview.txt
@@ -910,14 +910,23 @@ to test the effects of commit and rollback:
910 910
 
911 911
 * A ``TestCase``, on the other hand, does not truncate tables after a test.
912 912
   Instead, it encloses the test code in a database transaction that is rolled
913  
-  back at the end of the test.  It also prevents the code under test from
914  
-  issuing any commit or rollback operations on the database, to ensure that the
915  
-  rollback at the end of the test restores the database to its initial state.
  913
+  back at the end of the test. Both explicit commits like
  914
+  ``transaction.commit()`` and implicit ones that may be caused by
  915
+  ``Model.save()`` are replaced with a ``nop`` operation. This guarantees that
  916
+  the rollback at the end of the test restores the database to its initial
  917
+  state.
916 918
 
917 919
   When running on a database that does not support rollback (e.g. MySQL with the
918 920
   MyISAM storage engine), ``TestCase`` falls back to initializing the database
919 921
   by truncating tables and reloading initial data.
920 922
 
  923
+.. warning::
  924
+
  925
+    While ``commit`` and ``rollback`` operations still *appear* to work when
  926
+    used in ``TestCase``, no actual commit or rollback will be performed by the
  927
+    database. This can cause your tests to pass or fail unexpectedly. Always
  928
+    use ``TransactionalTestCase`` when testing transactional behavior.
  929
+
921 930
 .. note::
922 931
 
923 932
     .. versionchanged:: 1.5

0 notes on commit cd15a51

Please sign in to comment.
Something went wrong with that request. Please try again.