File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,9 @@ def __init__(
5858 self .environ = environ
5959 self .env_prefix = env_prefix
6060 self .file_values : typing .Dict [str , str ] = {}
61- if env_file is not None and os .path .isfile (env_file ):
61+ if env_file is not None :
62+ if not os .path .isfile (env_file ):
63+ raise FileNotFoundError (f"Config file '{ env_file } ' not found." )
6264 self .file_values = self ._read_file (env_file )
6365
6466 @typing .overload
Original file line number Diff line number Diff line change @@ -104,6 +104,13 @@ def cast_to_int(v) -> int:
104104 config .get ("BOOL_AS_INT" , cast = bool )
105105
106106
107+ def test_missing_env_file_raises (tmpdir ):
108+ path = os .path .join (tmpdir , ".env" )
109+
110+ with pytest .raises (FileNotFoundError , match = f"Config file '{ path } ' not found." ):
111+ Config (path )
112+
113+
107114def test_environ ():
108115 environ = Environ ()
109116
You can’t perform that action at this time.
0 commit comments