Skip to content
Myr

test_tracebacks.py

This file

Path

tests/test_tracebacks.py

55 lines 路 2.1 KiB 路 Python

Last changed by

馃敟 Remove support for Python 3.6 (#758)Sebasti谩n Ram铆rezbefore adoption13404a0

History of this file

Take 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    assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr212223def test_traceback_no_rich_short_disable():24    file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py"25    result = subprocess.run(26        [sys.executable, "-m", "coverage", "run", str(file_path)],27        stdout=subprocess.PIPE,28        stderr=subprocess.PIPE,29        encoding="utf-8",30        env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},31    )32    assert "return get_command(self)(*args, **kwargs)" not in result.stderr3334    assert "app()" in result.stderr35    assert "print(name + 3)" in result.stderr36    assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr373839def test_unmodified_traceback():40    file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py"41    result = subprocess.run(42        [sys.executable, "-m", "coverage", "run", str(file_path)],43        stdout=subprocess.PIPE,44        stderr=subprocess.PIPE,45        encoding="utf-8",46        env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},47    )48    assert "morty" in result.stdout, "the call to the first app should work normally"49    assert "return callback(**use_params)" in result.stderr, (50        "calling outside of Typer should show the normal traceback, "51        "even after the hook is installed"52    )53    assert "typer.main.get_command(broken_app)()" in result.stderr54    assert "print(name + 3)" in result.stderr55    assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr