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", "[email protected]"),
)
MANAGERS = ADMINS + (('Person1', '[email protected]'),)
# ... rest of settings
try:
from local_settings import *
except ImportError:
pass
and in <project>/local_settings.py
I have:
DEBUG = True
MANAGERS = (
('Me', '[email protected]'),
)
So, while working locally, the MANAGERS
setting should be (('Me', '[email protected]'),)
, 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', '[email protected]'),))
else:
self.assertEqual(settings.MANAGERS, (('Me', '[email protected]'), ('Person1', '[email protected]')))
The result is
AssertionError: (('Me', '[email protected]'),) != (('Me', '[email protected]'), ('Person1', '[email protected]'))
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', '[email protected]'),)
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?