Author: russellm
Date: 2010-10-30 08:03:37 -0500 (Sat, 30 Oct 2010)
New Revision: 14399

Modified:
   django/trunk/django/test/testcases.py
Log:
Reordered the shutdown process for tests so that all tests force a connection 
close. This is required to prevent some cross-test failures. Thanks to Florian 
Apolloner for the report and help tracking down the problem.

Modified: django/trunk/django/test/testcases.py
===================================================================
--- django/trunk/django/test/testcases.py       2010-10-30 07:19:04 UTC (rev 
14398)
+++ django/trunk/django/test/testcases.py       2010-10-30 13:03:37 UTC (rev 
14399)
@@ -305,9 +305,20 @@
         """ Performs any post-test things. This includes:
 
             * Putting back the original ROOT_URLCONF if it was changed.
+            * Force closing the connection, so that the next test gets
+              a clean cursor.
         """
         self._fixture_teardown()
         self._urlconf_teardown()
+        # Some DB cursors include SQL statements as part of cursor
+        # creation. If you have a test that does rollback, the effect
+        # of these statements is lost, which can effect the operation
+        # of tests (e.g., losing a timezone setting causing objects to
+        # be created with the wrong time).
+        # To make sure this doesn't happen, get a clean connection at the
+        # start of every test.
+        for connection in connections.all():
+            connection.close()
 
     def _fixture_teardown(self):
         pass
@@ -575,9 +586,6 @@
             transaction.rollback(using=db)
             transaction.leave_transaction_management(using=db)
 
-        for connection in connections.all():
-            connection.close()
-
 def _deferredSkip(condition, reason):
     def decorator(test_func):
         if not (isinstance(test_func, type) and issubclass(test_func, 
TestCase)):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to