test_tracebacks.py
This file
Path
tests/test_tracebacks.py
67 lines · 2.5 KiB · Python
Last changed by
👷♂️ Consistently use `sys.executable` to run subprocesses, needed by OpenSUSE (#408)Matthias Bachbefore adoption416c612
History of this fileTake it
1import os2import 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 stdout=subprocess.PIPE,12 stderr=subprocess.PIPE,13 encoding="utf-8",14 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},15 )16 assert "return get_command(self)(*args, **kwargs)" not in result.stderr1718 assert "typer.run(main)" in result.stderr19 assert "print(name + 3)" in result.stderr20 # TODO: when deprecating Python 3.6, remove second option21 assert (22 'TypeError: can only concatenate str (not "int") to str' in result.stderr23 or "TypeError: must be str, not int" in result.stderr24 )252627def test_traceback_no_rich_short_disable():28 file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py"29 result = subprocess.run(30 [sys.executable, "-m", "coverage", "run", str(file_path)],31 stdout=subprocess.PIPE,32 stderr=subprocess.PIPE,33 encoding="utf-8",34 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},35 )36 assert "return get_command(self)(*args, **kwargs)" not in result.stderr3738 assert "app()" in result.stderr39 assert "print(name + 3)" in result.stderr40 # TODO: when deprecating Python 3.6, remove second option41 assert (42 'TypeError: can only concatenate str (not "int") to str' in result.stderr43 or "TypeError: must be str, not int" in result.stderr44 )454647def test_unmodified_traceback():48 file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py"49 result = subprocess.run(50 [sys.executable, "-m", "coverage", "run", str(file_path)],51 stdout=subprocess.PIPE,52 stderr=subprocess.PIPE,53 encoding="utf-8",54 env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},55 )56 assert "morty" in result.stdout, "the call to the first app should work normally"57 assert "return callback(**use_params)" in result.stderr, (58 "calling outside of Typer should show the normal traceback, "59 "even after the hook is installed"60 )61 assert "typer.main.get_command(broken_app)()" in result.stderr62 assert "print(name + 3)" in result.stderr63 # TODO: when deprecating Python 3.6, remove second option64 assert (65 'TypeError: can only concatenate str (not "int") to str' in result.stderr66 or "TypeError: must be str, not int" in result.stderr67 )