Coverage for tests/test_tracebacks.py: 100%
26 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +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={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
14 )
15 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefghi
17 assert "typer.run(main)" in result.stderr 1abcdefghi
18 assert "print(name + 3)" in result.stderr 1abcdefghi
19 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi
22def test_traceback_no_rich_short_disable(): 1abcdefghi
23 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py" 1abcdefghi
24 result = subprocess.run( 1abcdefghi
25 [sys.executable, "-m", "coverage", "run", str(file_path)],
26 capture_output=True,
27 encoding="utf-8",
28 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
29 )
30 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefghi
32 assert "app()" in result.stderr 1abcdefghi
33 assert "print(name + 3)" in result.stderr 1abcdefghi
34 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi
37def test_unmodified_traceback(): 1abcdefghi
38 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py" 1abcdefghi
39 result = subprocess.run( 1abcdefghi
40 [sys.executable, "-m", "coverage", "run", str(file_path)],
41 capture_output=True,
42 encoding="utf-8",
43 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
44 )
45 assert "morty" in result.stdout, "the call to the first app should work normally" 1abcdefghi
46 assert "return callback(**use_params)" in result.stderr, ( 1abcdefghi
47 "calling outside of Typer should show the normal traceback, "
48 "even after the hook is installed"
49 )
50 assert "typer.main.get_command(broken_app)()" in result.stderr 1abcdefghi
51 assert "print(name + 3)" in result.stderr 1abcdefghi
52 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefghi