Coverage for tests/test_tracebacks.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
1import os 1abcdefghi
2import subprocess 1abcdefghi
3import sys 1abcdefghi
4from pathlib import Path 1abcdefghi
7def test_traceback_no_rich(): 1abcdefghi
8 file_path = Path(__file__).parent / "assets/type_error_no_rich.py" 1abcdefghi
9 result = subprocess.run( 1abcdefghi
10 [sys.executable, "-m", "coverage", "run", str(file_path)],
11 capture_output=True,
12 encoding="utf-8",
13 env={
14 **os.environ,
15 "TYPER_STANDARD_TRACEBACK": "",
16 "_TYPER_STANDARD_TRACEBACK": "",
17 },
18 )
19 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefghi
21 assert "app()" in result.stderr 1abcdefghi
22 assert "print(name + 3)" in result.stderr 1abcdefghi
23 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi
26def test_traceback_no_rich_short_disable(): 1abcdefghi
27 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py" 1abcdefghi
28 result = subprocess.run( 1abcdefghi
29 [sys.executable, "-m", "coverage", "run", str(file_path)],
30 capture_output=True,
31 encoding="utf-8",
32 env={
33 **os.environ,
34 "TYPER_STANDARD_TRACEBACK": "",
35 "_TYPER_STANDARD_TRACEBACK": "",
36 },
37 )
38 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefghi
40 assert "app()" in result.stderr 1abcdefghi
41 assert "print(name + 3)" in result.stderr 1abcdefghi
42 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi
45def test_unmodified_traceback(): 1abcdefghi
46 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py" 1abcdefghi
47 result = subprocess.run( 1abcdefghi
48 [sys.executable, "-m", "coverage", "run", str(file_path)],
49 capture_output=True,
50 encoding="utf-8",
51 env={
52 **os.environ,
53 "TYPER_STANDARD_TRACEBACK": "",
54 "_TYPER_STANDARD_TRACEBACK": "",
55 },
56 )
57 assert "morty" in result.stdout, "the call to the first app should work normally" 1abcdefghi
58 assert "return callback(**use_params)" in result.stderr, ( 1abcdefghi
59 "calling outside of Typer should show the normal traceback, "
60 "even after the hook is installed"
61 )
62 assert "typer.main.get_command(broken_app)()" in result.stderr 1abcdefghi
63 assert "print(name + 3)" in result.stderr 1abcdefghi
64 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi