Skip to content

Commit

Permalink
Merge pull request #361 from SebastiaanZ/attach-cause-to-improperly-c…
Browse files Browse the repository at this point in the history
…onfigured-exception

Attach cause to ImproperlyConfigured exception
  • Loading branch information
sergeyklay committed Jan 2, 2022
2 parents 0e9eba6 + f253eb3 commit dc3b775
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False):

try:
value = self.ENVIRON[var]
except KeyError:
except KeyError as exc:
if default is self.NOTSET:
error_msg = "Set the {} environment variable".format(var)
raise ImproperlyConfigured(error_msg)
raise ImproperlyConfigured(error_msg) from exc

value = default

Expand Down
1 change: 1 addition & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_not_present_without_default(self):
with pytest.raises(ImproperlyConfigured) as excinfo:
self.env('not_present')
assert str(excinfo.value) == 'Set the not_present environment variable'
assert excinfo.value.__cause__ is not None

def test_contains(self):
assert 'STR_VAR' in self.env
Expand Down

0 comments on commit dc3b775

Please sign in to comment.