summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2011-02-02 04:41:47 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2011-02-02 04:41:47 +0000
commite26de119f4dad4ec8bf2f8f24c1b6dd239eab04f (patch)
tree8f94b97b37f97529de9ea9a2a55faff230d9ce29
parentcda07b4cfaf92fe82f58d3d6ca6e64ea40502b0d (diff)
[1.2.X] 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.
Backport of r14399 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/test/testcases.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 1671b3aea4..8dcbf019d1 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -275,9 +275,20 @@ class TransactionTestCase(unittest.TestCase):
""" 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
@@ -541,6 +552,3 @@ class TestCase(TransactionTestCase):
for db in databases:
transaction.rollback(using=db)
transaction.leave_transaction_management(using=db)
-
- for connection in connections.all():
- connection.close()