Skip to content
Myr

test_tracebacks.py

This file

Path

tests/test_tracebacks.py

64 lines · 2.2 KiB · Python

Last changed by

✨ Add support for standard tracebacks via the env `TYPER_STANDARD_TRACEBACK` (#1299)Colin Nolanbefore adoptionde159dc

History of this file

Take it

The walk stopped after 200 commits: lines older than a5e41c5 point at it.

🔖 Release version 0.17.3Sebastián Ramírezbefore adoptiona5e41c5

lines 1–12why, one step back
1import os
2import subprocess3import sys4from pathlib import Path567def test_traceback_no_rich():8 file_path = Path(__file__).parent / "assets/type_error_no_rich.py"9 result = subprocess.run(10 [sys.executable, "-m", "coverage", "run", str(file_path)],11 capture_output=True,12 encoding="utf-8",

✨ Add support for standard tracebacks via the env `TYPER_STANDARD_TRACEBACK` (#1299)Colin Nolanbefore adoptionde159dc

lines 13–17why, one step back
13 env={
14 **os.environ,15 "TYPER_STANDARD_TRACEBACK": "",16 "_TYPER_STANDARD_TRACEBACK": "",17 },

🔖 Release version 0.17.3Sebastián Ramírezbefore adoptiona5e41c5

lines 18–20why, one step back
18 )
19 assert "return get_command(self)(*args, **kwargs)" not in result.stderr20

📝 Update docs to use `Typer()` more prominently (#1418)Sofie Van Landeghembefore adoptiondf2cb14

line 21why, one step back
21 assert "app()" in result.stderr

🔖 Release version 0.17.3Sebastián Ramírezbefore adoptiona5e41c5

lines 22–31why, one step back
22 assert "print(name + 3)" in result.stderr
23 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr242526def test_traceback_no_rich_short_disable():27 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py"28 result = subprocess.run(29 [sys.executable, "-m", "coverage", "run", str(file_path)],30 capture_output=True,31 encoding="utf-8",

✨ Add support for standard tracebacks via the env `TYPER_STANDARD_TRACEBACK` (#1299)Colin Nolanbefore adoptionde159dc

lines 32–36why, one step back
32 env={
33 **os.environ,34 "TYPER_STANDARD_TRACEBACK": "",35 "_TYPER_STANDARD_TRACEBACK": "",36 },

🔖 Release version 0.17.3Sebastián Ramírezbefore adoptiona5e41c5

lines 37–50why, one step back
37 )
38 assert "return get_command(self)(*args, **kwargs)" not in result.stderr3940 assert "app()" in result.stderr41 assert "print(name + 3)" in result.stderr42 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr434445def test_unmodified_traceback():46 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py"47 result = subprocess.run(48 [sys.executable, "-m", "coverage", "run", str(file_path)],49 capture_output=True,50 encoding="utf-8",

✨ Add support for standard tracebacks via the env `TYPER_STANDARD_TRACEBACK` (#1299)Colin Nolanbefore adoptionde159dc

lines 51–55why, one step back
51 env={
52 **os.environ,53 "TYPER_STANDARD_TRACEBACK": "",54 "_TYPER_STANDARD_TRACEBACK": "",55 },

🔖 Release version 0.17.3Sebastián Ramírezbefore adoptiona5e41c5

lines 56–64why, one step back
56 )
57 assert "morty" in result.stdout, "the call to the first app should work normally"58 assert "return callback(**use_params)" in result.stderr, (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.stderr63 assert "print(name + 3)" in result.stderr64 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr