MCPcopy Create free account
hub / github.com/pydantic/pydantic-settings / test_cli_app_exceptions

Function test_cli_app_exceptions

tests/test_source_cli.py:2540–2569  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2538
2539
2540def test_cli_app_exceptions():
2541 with pytest.raises(
2542 SettingsError, match='Error: NotPydanticModel is not subclass of BaseModel or pydantic.dataclasses.dataclass'
2543 ):
2544
2545 class NotPydanticModel: ...
2546
2547 CliApp.run(NotPydanticModel)
2548
2549 with pytest.raises(
2550 SettingsError,
2551 match=re.escape('Error: `cli_args` must be list[str] or None when `cli_settings_source` is not used'),
2552 ):
2553
2554 class Cfg(BaseModel): ...
2555
2556 CliApp.run(Cfg, cli_args={'my_arg': 'hello'})
2557
2558 with pytest.raises(SettingsError, match='Error: Child class is missing cli_cmd entrypoint'):
2559
2560 class Child(BaseModel):
2561 val: str
2562
2563 class Root(BaseModel):
2564 child: CliSubCommand[Child]
2565
2566 def cli_cmd(self) -> None:
2567 CliApp.run_subcommand(self)
2568
2569 CliApp.run(Root, cli_args=['child', '--val=hello'])
2570
2571
2572def test_cli_suppress(capsys, monkeypatch):

Callers

nothing calls this directly

Calls 1

runMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…