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

Function test_cli_help_string_format

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

Source from the content-addressed store, hash-verified

535
536
537def test_cli_help_string_format(capsys, monkeypatch):
538 class Cfg(BaseSettings, cli_parse_args=True, cli_prog_name='example.py'):
539 date_str: str = '%Y-%m-%d'
540
541 class MultilineDoc(BaseSettings, cli_parse_args=True, cli_prog_name='example.py'):
542 """
543 My
544 Multiline
545 Doc
546 """
547
548 with monkeypatch.context() as m:
549 m.setattr(sys, 'argv', ['example.py', '--help'])
550
551 with pytest.raises(SystemExit):
552 Cfg()
553
554 assert (
555 re.sub(r'0x\w+', '0xffffffff', capsys.readouterr().out, flags=re.MULTILINE)
556 == f"""usage: example.py [-h] [--date_str str]
557
558{ARGPARSE_OPTIONS_TEXT}:
559 -h, --help show this help message and exit
560 --date_str str (default: %Y-%m-%d)
561"""
562 )
563
564 with pytest.raises(SystemExit):
565 MultilineDoc()
566 assert (
567 capsys.readouterr().out
568 == f"""usage: example.py [-h]
569
570My
571Multiline
572Doc
573
574{ARGPARSE_OPTIONS_TEXT}:
575 -h, --help show this help message and exit
576"""
577 )
578
579 with pytest.raises(SystemExit):
580 cli_settings_source = CliSettingsSource(MultilineDoc, formatter_class=argparse.HelpFormatter)
581 MultilineDoc(_cli_settings_source=cli_settings_source(args=True))
582 assert (
583 capsys.readouterr().out
584 == f"""usage: example.py [-h]
585
586My Multiline Doc
587
588{ARGPARSE_OPTIONS_TEXT}:
589 -h, --help show this help message and exit
590"""
591 )
592
593
594def test_cli_help_union_of_models(capsys, monkeypatch):

Callers

nothing calls this directly

Calls 3

CliSettingsSourceClass · 0.90
MultilineDocClass · 0.85
CfgClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…