File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -2413,3 +2413,17 @@ class Root(BaseModel):
24132413 --deep-arg str (required)
24142414"""
24152415 )
2416+
2417+
2418+ def test_cli_json_optional_default ():
2419+ class Nested (BaseModel ):
2420+ foo : int = 1
2421+ bar : int = 2
2422+
2423+ class Options (BaseSettings ):
2424+ nested : Nested = Nested (foo = 3 , bar = 4 )
2425+
2426+ assert CliApp .run (Options , cli_args = []).model_dump () == {'nested' : {'foo' : 3 , 'bar' : 4 }}
2427+ assert CliApp .run (Options , cli_args = ['--nested' ]).model_dump () == {'nested' : {'foo' : 1 , 'bar' : 2 }}
2428+ assert CliApp .run (Options , cli_args = ['--nested={}' ]).model_dump () == {'nested' : {'foo' : 1 , 'bar' : 2 }}
2429+ assert CliApp .run (Options , cli_args = ['--nested.foo=5' ]).model_dump () == {'nested' : {'foo' : 5 , 'bar' : 2 }}
You can’t perform that action at this time.
0 commit comments