49
49
except ImportError :
50
50
yaml = None
51
51
try :
52
- import tomlkit
52
+ import tomli
53
53
except ImportError :
54
- tomlkit = None
54
+ tomli = None
55
55
56
56
57
57
class SimpleSettings (BaseSettings ):
@@ -1187,34 +1187,6 @@ def settings_customise_sources(
1187
1187
Settings ()
1188
1188
1189
1189
1190
- @pytest .mark .skipif (sys .version_info >= (3 , 11 ) or tomlkit , reason = 'tomlkit/tomllib is installed' )
1191
- def test_toml_not_installed (tmp_path ):
1192
- p = tmp_path / '.env'
1193
- p .write_text (
1194
- """
1195
- foobar = "Hello"
1196
- """
1197
- )
1198
-
1199
- class Settings (BaseSettings ):
1200
- foobar : str
1201
- model_config = SettingsConfigDict (toml_file = p )
1202
-
1203
- @classmethod
1204
- def settings_customise_sources (
1205
- cls ,
1206
- settings_cls : Type [BaseSettings ],
1207
- init_settings : PydanticBaseSettingsSource ,
1208
- env_settings : PydanticBaseSettingsSource ,
1209
- dotenv_settings : PydanticBaseSettingsSource ,
1210
- file_secret_settings : PydanticBaseSettingsSource ,
1211
- ) -> Tuple [PydanticBaseSettingsSource , ...]:
1212
- return (TomlConfigSettingsSource (settings_cls ),)
1213
-
1214
- with pytest .raises (ImportError , match = r'^tomlkit is not installed, run `pip install pydantic-settings\[toml\]`$' ):
1215
- Settings ()
1216
-
1217
-
1218
1190
def test_alias_set (env ):
1219
1191
class Settings (BaseSettings ):
1220
1192
foo : str = Field ('default foo' , validation_alias = 'foo_env' )
@@ -2159,7 +2131,7 @@ def settings_customise_sources(
2159
2131
assert s .model_dump () == {}
2160
2132
2161
2133
2162
- @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomlkit is None , reason = 'tomlkit /tomllib is not installed' )
2134
+ @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomli is None , reason = 'tomli /tomllib is not installed' )
2163
2135
def test_toml_file (tmp_path ):
2164
2136
p = tmp_path / '.env'
2165
2137
p .write_text (
@@ -2195,7 +2167,7 @@ def settings_customise_sources(
2195
2167
assert s .nested .nested_field == 'world!'
2196
2168
2197
2169
2198
- @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomlkit is None , reason = 'tomlkit /tomllib is not installed' )
2170
+ @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomli is None , reason = 'tomli /tomllib is not installed' )
2199
2171
def test_toml_no_file ():
2200
2172
class Settings (BaseSettings ):
2201
2173
model_config = SettingsConfigDict (toml_file = None )
@@ -2215,7 +2187,7 @@ def settings_customise_sources(
2215
2187
assert s .model_dump () == {}
2216
2188
2217
2189
2218
- @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomlkit is None , reason = 'tomlkit /tomllib is not installed' )
2190
+ @pytest .mark .skipif (sys .version_info <= (3 , 11 ) and tomli is None , reason = 'tomli /tomllib is not installed' )
2219
2191
def test_multiple_file_toml (tmp_path ):
2220
2192
p1 = tmp_path / '.env.toml1'
2221
2193
p2 = tmp_path / '.env.toml2'
0 commit comments