From ea667ee3aeed33bce1dd681d9c0ea42f9926db5a Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Sat, 21 Jul 2012 20:16:47 -0300 Subject: [PATCH] Made LiveServerTestCase to restore state on exit. 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. --- django/test/testcases.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django/test/testcases.py b/django/test/testcases.py index 95e751d384..0a0b029796 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1138,4 +1138,11 @@ class LiveServerTestCase(TransactionTestCase): 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()