Created
March 1, 2015 00:56
-
-
Save kane-c/191cde363fe555cd4fb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make the Django server from LiveServerTestCase multi-threaded | |
# so that you can make requests to yourself during tests without | |
# deadlocking. | |
# Note that this prevents being able to use in-memory sqlite for | |
# tests unless you use something like `/dev/shm` | |
# May cause other bugs too | |
from django.core.servers.basehttp import WSGIServer | |
from django.test import testcases | |
from django.utils.six.moves import socketserver | |
testcases.WSGIServer = type(str('WSGIServer'), | |
(socketserver.ThreadingMixIn, WSGIServer), {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Kane,
I am trying to use this snippet to implement threaded server for my django test runner. We have custom sql_flush function which we want to call after each test-case execution. It works fine when I am not using above snippet(no multi threaded approach), but when i put above snippet to my settings file, the default sql_flush is called from django library. Below is the code snippet. Can you help me fixing this?
from django.core.servers.basehttp import WSGIServer
from django.test import testcases
from django.utils.six.moves import socketserver
testcases.WSGIServer = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
from django.core.management import sql
sql.sql_flush = sql_flush_without_cms