File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 4444 NoDecode ,
4545 PydanticBaseSettingsSource ,
4646 SecretsSettingsSource ,
47- SettingsConfigDict ,
47+ SettingsConfigDict
4848)
4949from 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+
11061130def test_ignore_env_file_with_env_prefix_invalid (tmp_path ):
11071131 p = tmp_path / '.env'
11081132 p .write_text (prefix_test_env_invalid_file )
You can’t perform that action at this time.
0 commit comments