Skip to content

Commit

Permalink
Made LiveServerTestCase to restore state on exit.
Browse files Browse the repository at this point in the history
The piece of state is DB connections' allow_thread_sharing attribute
which gets munged test are run when in-memory SQLite databases.

Thanks Anssi for suggesting the possible root cause and Julien for
implementing the fix.
  • Loading branch information
ramiro committed Jul 21, 2012
1 parent 2b66443 commit ea667ee
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django/test/testcases.py
Expand Up @@ -1138,4 +1138,11 @@ def tearDownClass(cls):
if hasattr(cls, 'server_thread'):
# Terminate the live server's thread
cls.server_thread.join()

# Restore sqlite connections' non-sharability
for conn in connections.all():
if (conn.settings_dict['ENGINE'] == 'django.db.backends.sqlite3'
and conn.settings_dict['NAME'] == ':memory:'):
conn.allow_thread_sharing = False

super(LiveServerTestCase, cls).tearDownClass()

0 comments on commit ea667ee

Please sign in to comment.