diff --git a/tests/assets/type_error_no_rich_short_disable.py b/tests/assets/type_error_no_rich_short_disable.py new file mode 100644 index 0000000000..4985fe1945 --- /dev/null +++ b/tests/assets/type_error_no_rich_short_disable.py @@ -0,0 +1,16 @@ +import typer +import typer.main + +typer.main.rich = None + + +app = typer.Typer(pretty_errors_short=False) + + +@app.command() +def main(name: str = "morty"): + print(name + 3) + + +if __name__ == "__main__": + app() diff --git a/tests/assets/type_error_rich_pretty_disable.py b/tests/assets/type_error_rich_pretty_disable.py new file mode 100644 index 0000000000..dc0f0d6b8a --- /dev/null +++ b/tests/assets/type_error_rich_pretty_disable.py @@ -0,0 +1,12 @@ +import typer + +app = typer.Typer(pretty_errors_enable=False) + + +@app.command() +def main(name: str = "morty"): + print(name + 3) + + +if __name__ == "__main__": + app() diff --git a/tests/assets/type_error_rich_short_disable.py b/tests/assets/type_error_rich_short_disable.py new file mode 100644 index 0000000000..32c233dfc0 --- /dev/null +++ b/tests/assets/type_error_rich_short_disable.py @@ -0,0 +1,12 @@ +import typer + +app = typer.Typer(pretty_errors_short=False) + + +@app.command() +def main(name: str = "morty"): + print(name + 3) + + +if __name__ == "__main__": + app() diff --git a/tests/test_tracebacks.py b/tests/test_tracebacks.py index 2f692aefaa..137639c38a 100644 --- a/tests/test_tracebacks.py +++ b/tests/test_tracebacks.py @@ -12,7 +12,28 @@ def test_traceback_rich(): ) assert "return get_command(self)(*args, **kwargs)" not in result.stderr - assert "typer.run(main)" in result.stderr + assert "typer.run(main)" not in result.stderr + assert "print(name + 3)" in result.stderr + + # TODO: when deprecating Python 3.6, remove second option + assert ( + 'TypeError: can only concatenate str (not "int") to str' in result.stderr + or "TypeError: must be str, not int" in result.stderr + ) + assert "name = 'morty'" in result.stderr + + +def test_traceback_rich_pretty_short_disable(): + file_path = Path(__file__).parent / "assets/type_error_rich_short_disable.py" + result = subprocess.run( + ["coverage", "run", str(file_path)], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "return get_command(self)(*args, **kwargs)" not in result.stderr + + assert "app()" in result.stderr assert "print(name + 3)" in result.stderr # TODO: when deprecating Python 3.6, remove second option @@ -42,6 +63,25 @@ def test_traceback_no_rich(): ) +def test_traceback_no_rich_short_disable(): + file_path = Path(__file__).parent / "assets/type_error_no_rich_short_disable.py" + result = subprocess.run( + ["coverage", "run", str(file_path)], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "return get_command(self)(*args, **kwargs)" not in result.stderr + + assert "app()" in result.stderr + assert "print(name + 3)" in result.stderr + # TODO: when deprecating Python 3.6, remove second option + assert ( + 'TypeError: can only concatenate str (not "int") to str' in result.stderr + or "TypeError: must be str, not int" in result.stderr + ) + + def test_unmodified_traceback(): file_path = Path(__file__).parent / "assets/type_error_normal_traceback.py" result = subprocess.run( @@ -62,3 +102,22 @@ def test_unmodified_traceback(): 'TypeError: can only concatenate str (not "int") to str' in result.stderr or "TypeError: must be str, not int" in result.stderr ) + + +def test_rich_pretty_errors_disable(): + file_path = Path(__file__).parent / "assets/type_error_rich_pretty_disable.py" + result = subprocess.run( + ["coverage", "run", str(file_path)], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + ) + assert "return get_command(self)(*args, **kwargs)" in result.stderr + + assert "app()" in result.stderr + assert "print(name + 3)" in result.stderr + # TODO: when deprecating Python 3.6, remove second option + assert ( + 'TypeError: can only concatenate str (not "int") to str' in result.stderr + or "TypeError: must be str, not int" in result.stderr + )