Skip to content

Commit 4aaefa9

Browse files
committed
Fixed DB setup for spawned testing subprocess.
Closes #2030 Co-authored-by: @ashtonrobinson
1 parent cd44771 commit 4aaefa9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

channels/testing/live.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def make_application(*, static_wrapper):
1818
return application
1919

2020

21+
def set_database_connection():
22+
from django.conf import settings
23+
24+
test_db_name = settings.DATABASES["default"]["TEST"]["NAME"]
25+
settings.DATABASES["default"]["NAME"] = test_db_name
26+
27+
2128
class ChannelsLiveServerTestCase(TransactionTestCase):
2229
"""
2330
Does basically the same as TransactionTestCase but also launches a
@@ -58,7 +65,11 @@ def setUpClass(cls):
5865
make_application,
5966
static_wrapper=cls.static_wrapper if cls.serve_static else None,
6067
)
61-
cls._server_process = cls.ProtocolServerProcess(cls.host, get_application)
68+
cls._server_process = cls.ProtocolServerProcess(
69+
cls.host,
70+
get_application,
71+
setup=set_database_connection,
72+
)
6273
cls._server_process.start()
6374
while True:
6475
if not cls._server_process.ready.wait(timeout=1):

0 commit comments

Comments
 (0)