diff --git a/tests/test_vyper.py b/tests/test_vyper.py index 84392e6..ea1c018 100644 --- a/tests/test_vyper.py +++ b/tests/test_vyper.py @@ -294,6 +294,19 @@ def test_toml(self): self._init_toml() self.assertEqual("TOML Example", self.v.get("title")) + def test_env_override_default_subclass(self): + os.environ['CLASS.KEY2'] = 'newval2' + + self.v.set_default('class.key1', 'val1') + self.v.set_default('class.key2', 'val2') + self.v.set_default('class.key3', 'val3') + + self.v.bind_env('class.key1') + self.v.bind_env('class.key2') + self.v.bind_env('class.key3') + + self.assertEqual('val1', self.v.get('class.key1')) + def test_env(self): self._init_json() diff --git a/vyper/vyper.py b/vyper/vyper.py index 985598d..3059004 100644 --- a/vyper/vyper.py +++ b/vyper/vyper.py @@ -321,12 +321,14 @@ def _find_insensitive(self, key, source): return source.get(real_key) def _set_insensitive(self, key, val, source): - real_key = self._find_real_key(key, source) - if real_key is None: - msg = "No case insensitive variant of {0} found.".format(key) - raise KeyError(msg) + if source: + real_key = self._find_real_key(key, source) + if real_key is None: + msg = "No case insensitive variant of {0} found.".format(key) + raise KeyError(msg) - source[real_key] = val + source[real_key] = val + return True def _find(self, key): """Given a key, find the value @@ -385,8 +387,8 @@ def _find(self, key): real_key = self._find_real_key(path, temp) temp = temp[real_key] - self._set_insensitive(item["final_key"], val, temp) - found_in_env = True + if self._set_insensitive(item["final_key"], val, temp): + found_in_env = True else: log.debug("{0} env value unset".format(item["env_key"]))