Coverage for tests / test_tutorial / test_arguments / test_optional / test_tutorial003.py: 100%
28 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 subprocess 1abcdefghij
2import sys 1abcdefghij
4import pytest 1abcdefghij
5import typer 1abcdefghij
6import typer.core 1abcdefghij
7from typer.testing import CliRunner 1abcdefghij
9from docs_src.arguments.optional import tutorial003 as mod 1abcdefghij
11runner = CliRunner() 1abcdefghij
12app = mod.app 1abcdefghij
15def test_call_no_arg(): 1abcdefghij
16 result = runner.invoke(app) 1abcdefghij
17 assert result.exit_code != 0 1abcdefghij
18 assert "Missing argument 'name'." in result.output 1abcdefghij
21def test_call_no_arg_standalone(): 1abcdefghij
22 # Mainly for coverage
23 result = runner.invoke(app, standalone_mode=False) 1abcdefghij
24 assert result.exit_code != 0 1abcdefghij
27def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch): 1abcdefghij
28 # Mainly for coverage
29 monkeypatch.setattr(typer.core, "HAS_RICH", False) 1abcdefghij
30 result = runner.invoke(app) 1abcdefghij
31 assert result.exit_code != 0 1abcdefghij
32 assert "Error: Missing argument 'name'" in result.output 1abcdefghij
35def test_call_arg(): 1abcdefghij
36 result = runner.invoke(app, ["Camila"]) 1abcdefghij
37 assert result.exit_code == 0 1abcdefghij
38 assert "Hello Camila" in result.output 1abcdefghij
41def test_script(): 1abcdefghij
42 result = subprocess.run( 1abcdefghij
43 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
44 capture_output=True,
45 encoding="utf-8",
46 )
47 assert "Usage" in result.stdout 1abcdefghij