(capsys, monkeypatch)
| 1898 | |
| 1899 | |
| 1900 | def 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 | |
| 1922 | sub_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 | |
| 1940 | def test_cli_hide_none_type(capsys, monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…