Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include prefix in the ImproperlyConfigured error #520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading