Skip to content

Commit bdf4a25

Browse files
committed
Add test.
1 parent dc5579e commit bdf4a25

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_source_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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}}

0 commit comments

Comments
 (0)