I want to be able to set environment variables in my Django app for tests to be able to run. For instance, my views rely on several API keys.
There are ways to override settings during testing, but I don't want them defined in settings.py
as that is a security issue.
I've tried in my setup function to set these environment variables, but that doesn't work to give the Django application the values.
class MyTests(TestCase):
def setUp(self):
os.environ['TEST'] = '123' # doesn't propogate to app
When I test locally, I simply have an .env
file I run with
foreman start -e .env web
which supplies os.environ
with values. But in Django's unittest.TestCase
it does not have a way (that I know) to set that.
How can I get around this?