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

Function test_cli_avoid_json

tests/test_source_cli.py:1856–1897  ·  view source on GitHub ↗
(capsys, monkeypatch)

Source from the content-addressed store, hash-verified

1854
1855
1856def test_cli_avoid_json(capsys, monkeypatch):
1857 class SubModel(BaseModel):
1858 v1: int
1859
1860 class Settings(BaseSettings, cli_prog_name='example.py'):
1861 sub_model: SubModel
1862
1863 model_config = SettingsConfigDict(cli_parse_args=True)
1864
1865 with monkeypatch.context() as m:
1866 m.setattr(sys, 'argv', ['example.py', '--help'])
1867
1868 with pytest.raises(SystemExit):
1869 Settings(_cli_avoid_json=False)
1870
1871 assert (
1872 capsys.readouterr().out
1873 == f"""usage: example.py [-h] [--sub_model [JSON]] [--sub_model.v1 int]
1874
1875{ARGPARSE_OPTIONS_TEXT}:
1876 -h, --help show this help message and exit
1877
1878sub_model options:
1879 --sub_model [JSON] set sub_model from JSON string (default: {{}})
1880 --sub_model.v1 int (required)
1881"""
1882 )
1883
1884 with pytest.raises(SystemExit):
1885 Settings(_cli_avoid_json=True)
1886
1887 assert (
1888 capsys.readouterr().out
1889 == f"""usage: example.py [-h] [--sub_model.v1 int]
1890
1891{ARGPARSE_OPTIONS_TEXT}:
1892 -h, --help show this help message and exit
1893
1894sub_model options:
1895 --sub_model.v1 int (required)
1896"""
1897 )
1898
1899
1900def test_cli_remove_empty_groups(capsys, monkeypatch):

Callers

nothing calls this directly

Calls 1

SettingsClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…