Coverage for tests / test_tutorial / test_arguments / test_help / test_tutorial006.py: 100%
33 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import importlib 1abcdefghij
2import subprocess 1abcdefghij
3import sys 1abcdefghij
4from types import ModuleType 1abcdefghij
6import pytest 1abcdefghij
7import typer 1abcdefghij
8from typer.testing import CliRunner 1abcdefghij
10runner = CliRunner() 1abcdefghij
13@pytest.fixture( 1abcdefghij
14 name="mod",
15 params=[
16 pytest.param("tutorial006_non_an"),
17 pytest.param("tutorial006"),
18 ],
19)
20def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghij
21 module_name = f"docs_src.arguments.help.{request.param}" 1abcdefghij
22 mod = importlib.import_module(module_name) 1abcdefghij
23 return mod 1abcdefghij
26@pytest.fixture( 1abcdefghij
27 name="app",
28 params=[
29 pytest.param(None),
30 pytest.param("rich"),
31 ],
32)
33def get_app(mod: ModuleType, request: pytest.FixtureRequest) -> typer.Typer: 1abcdefghij
34 rich_markup_mode = request.param 1abcdefghij
35 app = typer.Typer(rich_markup_mode=rich_markup_mode) 1abcdefghij
36 app.command()(mod.main) 1abcdefghij
37 return app 1abcdefghij
40def test_help(app): 1abcdefghij
41 result = runner.invoke(app, ["--help"]) 1abcdefghij
42 assert result.exit_code == 0 1abcdefghij
43 assert "Usage: main [OPTIONS] [✨username✨]" in result.output 1abcdefghij
44 assert "NAME" not in result.output 1abcdefghij
45 assert "Arguments" in result.output 1abcdefghij
46 assert "[default: World]" in result.output 1abcdefghij
49def test_call_arg(app): 1abcdefghij
50 result = runner.invoke(app, ["Camila"]) 1abcdefghij
51 assert result.exit_code == 0 1abcdefghij
52 assert "Hello Camila" in result.output 1abcdefghij
55def test_script(mod: ModuleType): 1abcdefghij
56 result = subprocess.run( 1abcdefghij
57 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
58 capture_output=True,
59 encoding="utf-8",
60 )
61 assert "Usage" in result.stdout 1abcdefghij