0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Refs #32416 -- Added LiveServerTestCase._make_connections_override() hook.

This commit is contained in:
Chris Jerdonek 2021-04-12 08:41:39 +02:00 committed by Mariusz Felisiak
parent e4430f22c8
commit 71a936f9d8

View File

@ -1553,21 +1553,28 @@ class LiveServerTestCase(TransactionTestCase):
return cls.host
@classmethod
def setUpClass(cls):
super().setUpClass()
def _make_connections_override(cls):
connections_override = {}
for conn in connections.all():
# If using in-memory sqlite databases, pass the connections to
# the server thread.
if conn.vendor == 'sqlite' and conn.is_in_memory_db():
# Explicitly enable thread-shareability for this connection
conn.inc_thread_sharing()
connections_override[conn.alias] = conn
return connections_override
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._live_server_modified_settings = modify_settings(
ALLOWED_HOSTS={'append': cls.allowed_host},
)
cls._live_server_modified_settings.enable()
connections_override = cls._make_connections_override()
for conn in connections_override.values():
# Explicitly enable thread-shareability for this connection.
conn.inc_thread_sharing()
cls.server_thread = cls._create_server_thread(connections_override)
cls.server_thread.daemon = True
cls.server_thread.start()