* raise error on missing env file
* format
---------
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
self.environ = environ
self.env_prefix = env_prefix
self.file_values: typing.Dict[str, str] = {}
- if env_file is not None and os.path.isfile(env_file):
+ if env_file is not None:
+ if not os.path.isfile(env_file):
+ raise FileNotFoundError(f"Config file '{env_file}' not found.")
self.file_values = self._read_file(env_file)
@typing.overload
config.get("BOOL_AS_INT", cast=bool)
+def test_missing_env_file_raises(tmpdir):
+ path = os.path.join(tmpdir, ".env")
+
+ with pytest.raises(FileNotFoundError, match=f"Config file '{path}' not found."):
+ Config(path)
+
+
def test_environ():
environ = Environ()