Django has a feature to log each http request. Eg.:
INFO 2017-08-31 11:52:40,725 arnaud basehttp "GET /design/projects/ HTTP/1.1" 200 3852
Unfortunately, it seems to be disabled when running a LiveServerTestCase
. In order to ease the debugging of my end-to-end tests, I would like this feature to remain activated.
As it turns out, this behavior doesn't seem configurable. I couldn't find any doc on the subject, and resorted to dive inside Django.
(disclaimer: this is unofficial, therefore brittle)
Override the server_thread_class
attribute of your LiveServerTestCase
from django.core.servers.basehttp import ThreadedWSGIServer, WSGIRequestHandler
from django.test.testcases import LiveServerTestCase, LiveServerThread
class End2End(LiveServerTestCase):
class VersboseLiveServerThread(LiveServerThread):
def _create_server(self):
return ThreadedWSGIServer((self.host, self.port), WSGIRequestHandler, allow_reuse_address=False)
server_thread_class = VersboseLiveServerThread
This solution and the feeling that there is no way to configure that behavior properly stem from observing how LiveServerTestCase
is built (Django 1.11):
class LiveServerTestCase(TransactionTestCase):
# [...]
server_thread_class = LiveServerThread
class LiveServerThread(threading.Thread):
# [...]
def _create_server(self):
# an extension point returning the WSGIRequestHandler would have been nice :)
return ThreadedWSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False)
class QuietWSGIRequestHandler(WSGIRequestHandler):
def log_message(*args):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With