Skip to content

Commit

Permalink
Include prefix in the ImproperlyConfigured error
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack authored and sergeyklay committed Oct 25, 2024
1 parent 0ee9141 commit 8968660
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False):
value = self.ENVIRON[var_name]
except KeyError as exc:
if default is self.NOTSET:
error_msg = f'Set the {var} environment variable'
error_msg = f'Set the {var_name} environment variable'
raise ImproperlyConfigured(error_msg) from exc

value = default
Expand Down
7 changes: 7 additions & 0 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ def test_prefix(self):
self.env.prefix = 'PREFIX_'
assert self.env('TEST') == 'foo'

def test_prefix_and_not_present_without_default(self):
self.env.prefix = 'PREFIX_'
with pytest.raises(ImproperlyConfigured) as excinfo:
self.env('not_present')
assert str(excinfo.value) == 'Set the PREFIX_not_present environment variable'
assert excinfo.value.__cause__ is not None


class TestFileEnv(TestEnv):
def setup_method(self, method):
Expand Down

0 comments on commit 8968660

Please sign in to comment.