Skip to content

Commit

Permalink
Add the ability to use env variable pointing to a .env file (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
variable committed Sep 7, 2021
1 parent 64209ed commit e04667c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions environ/environ.py
Expand Up @@ -748,6 +748,7 @@ def read_env(cls, env_file=None, **overrides):
os.path.dirname(frame.f_back.f_code.co_filename),
'.env'
)
env_file = os.environ.get('ENV_FILE') or env_file
if not os.path.exists(env_file):
logger.info(
"%s doesn't exist - if you're not configuring your "
Expand Down
15 changes: 15 additions & 0 deletions tests/test_env.py
Expand Up @@ -351,3 +351,18 @@ class MyEnv(Env):

def test_singleton_environ(self):
assert self.CONFIG is self.env.ENVIRON


class FileEnvByEnvVarTests(TestEnv):

def setup_method(self, method):
super(FileEnvByEnvVarTests, self).setUp()
with open('./tmp/test_env.txt') as env_file:
env_file.writeline('VAR=TEST')
Env.ENVIRON = {}
os.environ['ENV_FILE'] = './tmp/test_env.txt'
self.env = Env()

def test_read_env(self):
assert_type_and_value(str, 'TEST', self.env('VAR'))

0 comments on commit e04667c

Please sign in to comment.