import os
import typing
+import warnings
from pathlib import Path
self.file_values: typing.Dict[str, str] = {}
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)
+ warnings.warn(f"Config file '{env_file}' not found.")
+ else:
+ self.file_values = self._read_file(env_file)
@typing.overload
def __call__(self, key: str, *, default: None) -> str | None:
def test_missing_env_file_raises(tmpdir: Path) -> None:
path = os.path.join(tmpdir, ".env")
- with pytest.raises(FileNotFoundError, match=f"Config file '{path}' not found."):
+ with pytest.warns(UserWarning, match=f"Config file '{path}' not found."):
Config(path)