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

3

20

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

Batfish answered 28/1, 2013 at 16:40 Comment(0)
B
19

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!

Batfish answered 29/1, 2013 at 15:39 Comment(0)
M
8

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

March answered 4/11, 2016 at 17:29 Comment(0)
F
0

I'm not terribly familiar with the Selenium test suite, myself, but I do know that if you are deploying the application and your IP address is not registered in the "INTERNAL_IPS" tuple, you may not see tracebacks even if DEBUG is set to True. When you use Django's runserver, it adds your local machine to the INTERNAL_IPS setting automatically, however normally this is an empty tuple. My bet is that Selenium isn't doing that for you and that may be why you don't see tracebacks. I'd try adding that, if you haven't already.

Something like this should work fine:

INTERNAL_IPS = ('127.0.0.1',)

Django Settings (INTERNAL_IPS)

Fash answered 28/1, 2013 at 17:44 Comment(2)
sadly i have already that in my settings.py :| i'll try to debug it to see if it is set correctly when the test is runningBatfish
i've updated the question, django social auth is not involved, i get the 500 even if i put an indent error in the first view i reachBatfish

© 2022 - 2024 — McMap. All rights reserved.