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

Function test_cli_remove_empty_groups

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

Source from the content-addressed store, hash-verified

1898
1899
1900def test_cli_remove_empty_groups(capsys, monkeypatch):
1901 class SubModel(BaseModel):
1902 pass
1903
1904 class Settings(BaseSettings, cli_prog_name='example.py'):
1905 sub_model: SubModel
1906
1907 model_config = SettingsConfigDict(cli_parse_args=True)
1908
1909 with monkeypatch.context() as m:
1910 m.setattr(sys, 'argv', ['example.py', '--help'])
1911
1912 with pytest.raises(SystemExit):
1913 Settings(_cli_avoid_json=False)
1914
1915 assert (
1916 capsys.readouterr().out
1917 == f"""usage: example.py [-h] [--sub_model [JSON]]
1918
1919{ARGPARSE_OPTIONS_TEXT}:
1920 -h, --help show this help message and exit
1921
1922sub_model options:
1923 --sub_model [JSON] set sub_model from JSON string (default: {{}})
1924"""
1925 )
1926
1927 with pytest.raises(SystemExit):
1928 Settings(_cli_avoid_json=True)
1929
1930 assert (
1931 capsys.readouterr().out
1932 == f"""usage: example.py [-h]
1933
1934{ARGPARSE_OPTIONS_TEXT}:
1935 -h, --help show this help message and exit
1936"""
1937 )
1938
1939
1940def test_cli_hide_none_type(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…