diff --git a/environ/environ.py b/environ/environ.py index a3d64f2d..32a1b7ad 100644 --- a/environ/environ.py +++ b/environ/environ.py @@ -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 diff --git a/tests/test_env.py b/tests/test_env.py index 85e0499f..ac383773 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -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):