Skip to content

Commit

Permalink
Fixed issue when env var explicitly set to empty string.
Browse files Browse the repository at this point in the history
Fixes sloria#71
  • Loading branch information
hvtuananh committed Apr 30, 2019
1 parent cf0b5e8 commit d4ed648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion environs.py
Expand Up @@ -46,7 +46,10 @@ def method(self, name, default=ma.missing, subcast=None, **kwargs):
raise EnvError(
'Environment variable "{}" not set'.format(proxied_key or parsed_key)
)
value = raw_value or field.missing
if raw_value or raw_value == "":
value = raw_value
else:
value = field.missing
if preprocess:
value = preprocess(value, subcast=subcast, **kwargs)
try:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_environs.py
Expand Up @@ -47,6 +47,10 @@ def test_basic(self, set_env, env):
set_env({"STR": "foo"})
assert env.str("STR") == "foo"

def test_empty_str(self, set_env, env):
set_env({"STR": ""})
assert env.str("STR") == ""

def test_int_cast(self, set_env, env):
set_env({"INT": "42"})
assert env.int("INT") == 42
Expand Down

0 comments on commit d4ed648

Please sign in to comment.