Thursday, June 20, 2013

First Post: Overriding Django DEBUG setting for unit tests

I have found a line of code so nice, that I decided to make a blog for it.

Problem: Running selenium tests with django using django-selenium  test runner. As you might know this runs a test server for your selenium tests the same way good old fashioned django unit tests does it.
If you get a 500 it is really hard to debug ot having access to that instance of the server also DEBUG is set to False by Django for tests.

Solution: It is possible to really easily override where necessary:


from django.test.utils import override_settings
from django.conf import settings
class TestSomething(TestCase):
    @override_settings(DEBUG=True)
    def test_debug(self):
        assert settings.DEBUG

source: 

http://stackoverflow.com/questions/7447134/how-do-you-set-debug-to-true-when-running-a-django-test