Skip to content

Commit 12d5537

Browse files
committed
test source included in line_error context
1 parent 112b07e commit 12d5537

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_settings.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
NoDecode,
4545
PydanticBaseSettingsSource,
4646
SecretsSettingsSource,
47-
SettingsConfigDict,
47+
SettingsConfigDict
4848
)
4949
from pydantic_settings.sources import DefaultSettingsSource, SettingsError
5050

@@ -1103,6 +1103,30 @@ class Settings(BaseSettings):
11031103
]
11041104

11051105

1106+
def test_env_file_with_env_prefix_invalid_with_sources(tmp_path):
1107+
p = tmp_path / '.env'
1108+
p.write_text(prefix_test_env_invalid_file)
1109+
1110+
class Settings(BaseSettings):
1111+
a: str
1112+
b: str
1113+
c: str
1114+
1115+
model_config = SettingsConfigDict(env_file=p, env_prefix='prefix_', validate_each_source=True)
1116+
1117+
with pytest.raises(ValidationError) as exc_info:
1118+
Settings()
1119+
assert exc_info.value.errors(include_url=False) == [
1120+
{
1121+
'type': 'extra_forbidden',
1122+
'loc': ('f',),
1123+
'msg': 'Extra inputs are not permitted',
1124+
'input': 'random value',
1125+
'ctx': {'source': 'DotEnvSettingsSource'}
1126+
}
1127+
]
1128+
1129+
11061130
def test_ignore_env_file_with_env_prefix_invalid(tmp_path):
11071131
p = tmp_path / '.env'
11081132
p.write_text(prefix_test_env_invalid_file)

0 commit comments

Comments
 (0)