Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (LiveServerTestCase 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 
INTERNAL_IPS = ('127.0.0.1',)

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).

like image 396
apelliciari Avatar asked Jan 28 '13 16:01

apelliciari


2 Answers

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!

like image 62
apelliciari Avatar answered Oct 19 '22 07:10

apelliciari


I ran into the same issue and it is now possible to override settings.

based on your example you would import override_settings and place the decorator above the class:

from django.test import override_settings

@override_settings(DEBUG=True)
class SeleniumLiveServerTestCase(LiveServerTestCase):

    ...

details in django docs

like image 38
udo Avatar answered Oct 19 '22 07:10

udo