Closed ryanmsnyder closed 3 years ago
yes, it's throw exception. i have test for that.
https://github.com/thesimj/envyaml/blob/master/tests/test_envyaml.py
def test_it_should_raise_exception_in_strict_mode():
with pytest.raises(ValueError):
EnvYAML("tests/env.ignored.yaml")
please, give more detail about this issue. Like Python version, example of your env.yaml file, etc..
python version: 3.8
env.yaml contents:
test1:
test2:
main.py contents:
from envyaml import EnvYAML
env = EnvYAML('env.yaml', strict=True)
test1 = env['test1']
print(test1)
test2 = env['test2']
print(test2)
result:
None
None
Thank, this is a good example.
I don't see an issue here, since non existing env variable are covered by strict
and will throw exception, but in this case, this is more in way of No Value
issue that is normal for YAML format. You are allow to create None
value.
what you will think?
Ah, this is my mistake. I was thinking that strict mode was to prevent empty values (None) in the yaml file but it is to throw an error if an environment variable doesn't exist. Thank you @thesimj.
your welcome
According to the parameter 'strict' in class EnvYAML, it should throw an exception:
:param bool strict: use strict mode and throw exception when have unset variable, by default true