(capsys, monkeypatch)
| 1854 | |
| 1855 | |
| 1856 | def 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 | |
| 1878 | sub_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 | |
| 1894 | sub_model options: |
| 1895 | --sub_model.v1 int (required) |
| 1896 | """ |
| 1897 | ) |
| 1898 | |
| 1899 | |
| 1900 | def test_cli_remove_empty_groups(capsys, monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…