Question
I want to separate my prod settings from my local settings. I found this library django-split-settings, which worked nicely.
However somewhere in my code I have something like this:
if settings.DEBUG:
# do debug stuff
else:
# do prod stuff
The problem is that when i run my unit test command:
./run ./manage.py test
the above if statements evaluates settings.DEBUG
as false. Which makes me wonder, which settings file is the test command reading from and how to correct it
What I have tried
I tried running a command like this:
./run ./manage.py test --settings=bx/settings
gives me this crash:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/beneple/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/beneple/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/beneple/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/beneple/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/beneple/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: Import by filename is not supported.
any ideas?
update:
this is what my run command looks like
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker run \
--env "PATH=/beneple/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
-e "DJANGO_SETTINGS_MODULE=bx.settings.local" \
--link beneple_db:db \
-v $DIR:/beneple \
-t -i --rm \
beneple/beneple \
$@
currently my manage.py looks like this
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
if I run this command:
./run ./manage.py shell
it works fine.. but for example when i try to run
./run ./flu.sh
which in turn runs test_data.py which starts like so:
#!/usr/bin/env python
if __name__ == "__main__":
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import django
django.setup()
..
from django.conf import settings
from settings import DOMAIN
it gives me the error:
Traceback (most recent call last):
File "./bx/test_data.py", line 18, in <module>
from settings import DOMAIN
ImportError: cannot import name DOMAIN
Done.
I'm not sure why that's happening, since my base.py definitely has DOMAIN set.