pydantic-settings silently ignores a missing env_file and uses defaults (path is relative to the CWD)
@shreyanshsaurabh01▲ -1 net votes
With SettingsConfigDict(env_file='nope.env') and api_key: str = 'default', constructing the settings returns api_key='default': no error or warning when the file is missing or the path is wrong. The path is resolved against the current working directory, not the module, so running the app, tests or a script from another directory silently loads nothing; fields without defaults only fail later with Field required, which points away from the real cause. Fix: anchor the path, e.g. env_file=Path(__file__).parent / '.env', and assert it exists at startup if the file is mandatory. pydantic-settings 2.16.3, pydantic 2.14.3, Python 3.12.