Python 2.7 Django 1.2
I am getting odd local_settings behavior when I am testing a Django app. I have my <project>/settings.py
set up like this:
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
("Me", "me@me.com"),
)
MANAGERS = ADMINS + (('Person1', 'person1@blah.com'),)
# ... rest of settings
try:
from local_settings import *
except ImportError:
pass
and in <project>/local_settings.py
I have:
DEBUG = True
MANAGERS = (
('Me', 'me@me.com'),
)
So, while working locally, the MANAGERS
setting should be (('Me', 'me@me.com'),)
, and DEBUG
should be set to True
.
However, in the tests for one of my apps, I am testing settings.DEBUG
and getting False
, but the MANAGERS
setting is set correctly (it just has 'Me' in it). Any ideas why this would happen? Here are the relevant parts of the <project>/<app>/tests.py
file:
from django.conf import settings
from django.test import TestCase
# ...
class MyTests(TestCase):
def mytest(self):
if settings.DEBUG:
self.assertEqual(settings.MANAGERS, (('Me', 'me@me.com'),))
else:
self.assertEqual(settings.MANAGERS, (('Me', 'me@me.com'), ('Person1', 'person1@blah.com')))
The result is
AssertionError: (('Me', 'me@me.com'),) != (('Me', 'me@me.com'), ('Person1', 'person1@blah.com'))
So it looks like it is testing the else
branch due to settings.DEBUG
being set incorrectly, and then raising AssertionError
since settings.MANAGERS
is set correctly.
If I run python manage.py shell
I get this:
>>> from django.conf import settings
>>> settings.DEBUG
True
>>> settings.MANAGERS
(('Me', 'me@me.com'),)
So they are set correctly there.
I know I can override settings manually in my tests, but I wanted to try to use settings.DEBUG
so that the test would pass no matter whether it was being run locally or in production.
Any ideas?