apelliciari apelliciari - 1 year ago 56
Python Question

Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests?

I'm writing some tests with Selenium.

When i run my selenium tests (

type) and i have some error in my code (not in the test, i mean in the code executed, like the homepage view i reach with selenium) i get the 500 template (that usually i get when i have DEBUG = False) even if i have:

DEBUG = True

I'm stuck with that and i can't see why my test failed (because in the public 500 i don't show the exceptions).

Why does it behave like that? Where can i look to resolve?

When i run the runserver it works perfectly (i get the tracebacks).

Answer Source

from the django docs https://docs.djangoproject.com/en/1.4/topics/testing/#other-test-conditions

Seems not possible to override this at this moment, even with https://docs.djangoproject.com/en/1.4/topics/testing/#django.test.utils.override_settings

the only way to see the debug information when it's returned a 500 response is by logging it.

edit: i've found a way to set DEBUG = True in my selenium tests. In my subclass, i override the constructor and change the setting.

from django.conf import settings

class SeleniumLiveServerTestCase(LiveServerTestCase):

    def __init__(self, *args, **kwargs):
        super(SeleniumLiveServerTestCase, self).__init__(*args, **kwargs)
        if settings.DEBUG == False:
            settings.DEBUG = True

it's ugly but works!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download