Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20316 - Clarified transaction behavior of TestCase.

Thanks uberj@ for the report and lolek09 for the patch.
  • Loading branch information...
commit dffdca1109a2111f104f2419d081c0f971537fec 1 parent 5a62236
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
@@ -925,14 +925,23 @@ to test the effects of commit and rollback:
925 925
 
926 926
 * A ``TestCase``, on the other hand, does not truncate tables after a test.
927 927
   Instead, it encloses the test code in a database transaction that is rolled
928  
-  back at the end of the test.  It also prevents the code under test from
929  
-  issuing any commit or rollback operations on the database, to ensure that the
930  
-  rollback at the end of the test restores the database to its initial state.
  928
+  back at the end of the test. Both explicit commits like
  929
+  ``transaction.commit()`` and implicit ones that may be caused by
  930
+  ``Model.save()`` are replaced with a ``nop`` operation. This guarantees that
  931
+  the rollback at the end of the test restores the database to its initial
  932
+  state.
931 933
 
932 934
   When running on a database that does not support rollback (e.g. MySQL with the
933 935
   MyISAM storage engine), ``TestCase`` falls back to initializing the database
934 936
   by truncating tables and reloading initial data.
935 937
 
  938
+.. warning::
  939
+
  940
+    While ``commit`` and ``rollback`` operations still *appear* to work when
  941
+    used in ``TestCase``, no actual commit or rollback will be performed by the
  942
+    database. This can cause your tests to pass or fail unexpectedly. Always
  943
+    use ``TransactionalTestCase`` when testing transactional behavior.
  944
+
936 945
 .. note::
937 946
 
938 947
     .. versionchanged:: 1.5

0 notes on commit dffdca1

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