test_tracebacks.py
This file
Path
tests/test_tracebacks.py
66 lines · 2.4 KiB · Python
Last changed by
✨ Refactor and document handling pretty exceptions (#422)Sebastián Ramírezbefore adoptionc750f82
History of this fileTake it
✨ Richify, add integrations with Rich everywhere (#419)Sebastián Ramírezbefore adoption6208b5b
line 1why, one step back1import os✨ Add pretty error tracebacks for user errors and support for Rich (#412)Sebastián Ramírezbefore adoption252ed30
lines 2–12why, one step back2import subprocess3from pathlib import Path456def test_traceback_no_rich():7 file_path = Path(__file__).parent / "assets/type_error_no_rich.py"8 result = subprocess.run(9 ["coverage", "run", str(file_path)],10 stdout=subprocess.PIPE,11 stderr=subprocess.PIPE,12 encoding="utf-8",✨ Richify, add integrations with Rich everywhere (#419)Sebastián Ramírezbefore adoption6208b5b
line 13why, one step back13 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},✨ Add pretty error tracebacks for user errors and support for Rich (#412)Sebastián Ramírezbefore adoption252ed30
lines 14–25why, one step back14 )15 assert "return get_command(self)(*args, **kwargs)" not in result.stderr1617 assert "typer.run(main)" in result.stderr18 assert "print(name + 3)" in result.stderr19 # TODO: when deprecating Python 3.6, remove second option20 assert (21 'TypeError: can only concatenate str (not "int") to str' in result.stderr22 or "TypeError: must be str, not int" in result.stderr23 )2425✨ Allow configuring pretty errors when creating the Typer instance (#416)Sebastián Ramírezbefore adoption95a5233
lines 26–32why, one step back26def 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 ["coverage", "run", str(file_path)],30 stdout=subprocess.PIPE,31 stderr=subprocess.PIPE,32 encoding="utf-8",✨ Richify, add integrations with Rich everywhere (#419)Sebastián Ramírezbefore adoption6208b5b
line 33why, one step back33 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},✨ Allow configuring pretty errors when creating the Typer instance (#416)Sebastián Ramírezbefore adoption95a5233
lines 34–45why, one step back34 )35 assert "return get_command(self)(*args, **kwargs)" not in result.stderr3637 assert "app()" in result.stderr38 assert "print(name + 3)" in result.stderr39 # TODO: when deprecating Python 3.6, remove second option40 assert (41 'TypeError: can only concatenate str (not "int") to str' in result.stderr42 or "TypeError: must be str, not int" in result.stderr43 )4445✨ Add pretty error tracebacks for user errors and support for Rich (#412)Sebastián Ramírezbefore adoption252ed30
lines 46–52why, one step back46def test_unmodified_traceback():47 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py"48 result = subprocess.run(49 ["coverage", "run", str(file_path)],50 stdout=subprocess.PIPE,51 stderr=subprocess.PIPE,52 encoding="utf-8",✨ Richify, add integrations with Rich everywhere (#419)Sebastián Ramírezbefore adoption6208b5b
line 53why, one step back53 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},✨ Add pretty error tracebacks for user errors and support for Rich (#412)Sebastián Ramírezbefore adoption252ed30
lines 54–66why, one step back54 )55 assert "morty" in result.stdout, "the call to the first app should work normally"56 assert "return callback(**use_params)" in result.stderr, (57 "calling outside of Typer should show the normal traceback, "58 "even after the hook is installed"59 )60 assert "typer.main.get_command(broken_app)()" in result.stderr61 assert "print(name + 3)" in result.stderr62 # TODO: when deprecating Python 3.6, remove second option63 assert (64 'TypeError: can only concatenate str (not "int") to str' in result.stderr65 or "TypeError: must be str, not int" in result.stderr66 )