Coverage for tests / test_tutorial / test_exceptions / test_tutorial002.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 os 1abcdefghij
2import subprocess 1abcdefghij
3import sys 1abcdefghij
4from pathlib import Path 1abcdefghij
6import pytest 1abcdefghij
7from typer.testing import CliRunner 1abcdefghij
9from docs_src.exceptions import tutorial002 as mod 1abcdefghij
11runner = CliRunner() 1abcdefghij
14def test_traceback_rich(): 1abcdefghij
15 file_path = Path(mod.__file__) 1abcdefghij
16 result = subprocess.run( 1abcdefghij
17 [sys.executable, "-m", "coverage", "run", str(file_path)],
18 capture_output=True,
19 encoding="utf-8",
20 env={
21 **os.environ,
22 "TYPER_STANDARD_TRACEBACK": "",
23 "_TYPER_STANDARD_TRACEBACK": "",
24 },
25 )
26 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefghij
28 assert "app()" not in result.stderr 1abcdefghij
29 assert "print(name + 3)" in result.stderr 1abcdefghij
30 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghij
31 assert "name = 'morty'" in result.stderr 1abcdefghij
34@pytest.mark.parametrize( 1abcdefghij
35 "env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
36)
37def test_standard_traceback_env_var(env_var: str): 1abcdefghij
38 file_path = Path(mod.__file__) 1abcdefghij
39 result = subprocess.run( 1abcdefghij
40 [sys.executable, "-m", "coverage", "run", str(file_path)],
41 capture_output=True,
42 encoding="utf-8",
43 env={**os.environ, env_var: "1"},
44 )
45 assert "return get_command(self)(*args, **kwargs)" in result.stderr 1abcdefghij
47 assert "app()" in result.stderr 1abcdefghij
48 assert "print(name + 3)" in result.stderr 1abcdefghij
49 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghij
50 assert "name = 'morty'" not in result.stderr 1abcdefghij
53def test_script(): 1abcdefghij
54 result = subprocess.run( 1abcdefghij
55 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
56 capture_output=True,
57 encoding="utf-8",
58 )
59 assert "Usage" in result.stdout 1abcdefghij