Skip to content

Commit 4c8f5e4

Browse files
Enrico StaussEnrico Stauss
authored andcommitted
Add test to demonstrate non-deterministic nature of InitSettingsSource
1 parent c22cef4 commit 4c8f5e4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,21 @@ class Example(BaseSettings):
699699
assert Example(name='john', PREFIX_SURNAME='doe').model_dump() == {'name': 'john', 'last_name': 'doe'}
700700

701701

702+
@pytest.mark.xfail(
703+
reason='This test is expected to fail in some sessions due to `InitSettingsSource`s non-deterministic behaviour.'
704+
"Simply repeating through parameterization won't help as the underlying reason is the non-deterministic "
705+
'nature of python sets, which will remain constant within the same session.'
706+
)
707+
def test_init_kwargs_alias_resolution_deterministic():
708+
class Example(BaseSettings):
709+
name: str
710+
last_name: str = Field(validation_alias=AliasChoices('surname', 'last_name'))
711+
712+
result = Example(name='john', surname='doe', last_name='smith').model_dump()
713+
714+
assert result == {'name': 'john', 'last_name': 'doe'}
715+
716+
702717
def test_alias_nested_model_default_partial_update():
703718
class SubModel(BaseModel):
704719
v1: str = 'default'

0 commit comments

Comments
 (0)