Django's test runner overrides your settings to force DEBUG to be True, which I understand the intention behind, but it is occasionally annoying. One solution for those cases is to use `override_settings`, but that has very weird effects when using `LiveServerTestCase`.
Minimal repro:
django-admin.py startproject myproj
cd myproj
vi tests.pyIn tests.py:
from django.test import LiveServerTestCase
from selenium import webdriver
from django.test.utils import override_settings
@override_settings(DEBUG=True)
class MinimalTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
def test_admin_site_is_there(self):
self.browser.get(self.live_server_url + '/admin')
self.assertIn('Django administration', self.browser.find_element_by_tag_name('body').text)
Change DEBUG=True to DEBUG=False and this passes. But, as-is, you get:
File "/tmp/myproj/test1.py", line 18, in test_admin_site_is_there
self.assertIn('Django administration', self.browser.find_element_by_tag_name('body').text)
AssertionError: 'Django administration' not found in 'Page not found (404)\nRequest Method: GET\nRequest URL: http://localhost:8081/admin\n"admin" does not exist\nYou\'re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.'
I'm just using the admin URL because it's one that is activated by default. Normal URLs, eg a home page view, also return 404s. What's going on?