Skip to content

Commit

Permalink
[1.2.X] Reordered the shutdown process for tests so that all tests fo…
Browse files Browse the repository at this point in the history
…rce 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
  • Loading branch information
freakboy3742 committed Feb 2, 2011
1 parent cda07b4 commit e26de11
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions django/test/testcases.py
Expand Up @@ -275,9 +275,20 @@ def _post_teardown(self):
""" 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
Expand Down Expand Up @@ -541,6 +552,3 @@ def _fixture_teardown(self):
for db in databases:
transaction.rollback(using=db)
transaction.leave_transaction_management(using=db)

for connection in connections.all():
connection.close()

0 comments on commit e26de11

Please sign in to comment.