Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reordered the shutdown process for tests so that all tests force a co…

…nnection close. This is required to prevent some cross-test failures. Thanks to Florian Apolloner for the report and help tracking down the problem.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fffbbe406232fb7403ed33123cd21f9c0996f627 1 parent 52e0bcb
Russell Keith-Magee authored

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

  1. 14  django/test/testcases.py
14  django/test/testcases.py
@@ -305,9 +305,20 @@ def _post_teardown(self):
305 305
         """ Performs any post-test things. This includes:
306 306
 
307 307
             * Putting back the original ROOT_URLCONF if it was changed.
  308
+            * Force closing the connection, so that the next test gets
  309
+              a clean cursor.
308 310
         """
309 311
         self._fixture_teardown()
310 312
         self._urlconf_teardown()
  313
+        # Some DB cursors include SQL statements as part of cursor
  314
+        # creation. If you have a test that does rollback, the effect
  315
+        # of these statements is lost, which can effect the operation
  316
+        # of tests (e.g., losing a timezone setting causing objects to
  317
+        # be created with the wrong time).
  318
+        # To make sure this doesn't happen, get a clean connection at the
  319
+        # start of every test.
  320
+        for connection in connections.all():
  321
+            connection.close()
311 322
 
312 323
     def _fixture_teardown(self):
313 324
         pass
@@ -575,9 +586,6 @@ def _fixture_teardown(self):
575 586
             transaction.rollback(using=db)
576 587
             transaction.leave_transaction_management(using=db)
577 588
 
578  
-        for connection in connections.all():
579  
-            connection.close()
580  
-
581 589
 def _deferredSkip(condition, reason):
582 590
     def decorator(test_func):
583 591
         if not (isinstance(test_func, type) and issubclass(test_func, TestCase)):

0 notes on commit fffbbe4

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