Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorial/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ TypeError: can only concatenate str (not "int") to str

</div>

You could also achieve the same with the environment variable `_TYPER_STANDARD_TRACEBACK=1`.
You could also achieve the same with the environment variable `TYPER_STANDARD_TRACEBACK=1` (or by setting the deprecated variable `_TYPER_STANDARD_TRACEBACK=1`).

This will work for any other Typer program too, in case you need to debug a problem in a Typer program made by someone else:

<div class="termy">

```console
export _TYPER_STANDARD_TRACEBACK=1
export TYPER_STANDARD_TRACEBACK=1
$ python main.py


Expand Down
18 changes: 15 additions & 3 deletions tests/test_tracebacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def test_traceback_no_rich():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" not in result.stderr

Expand All @@ -25,7 +29,11 @@ def test_traceback_no_rich_short_disable():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" not in result.stderr

Expand All @@ -40,7 +48,11 @@ def test_unmodified_traceback():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "morty" in result.stdout, "the call to the first app should work normally"
assert "return callback(**use_params)" in result.stderr, (
Expand Down
15 changes: 11 additions & 4 deletions tests/test_tutorial/test_exceptions/test_tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from pathlib import Path

import pytest
from typer.testing import CliRunner

from docs_src.exceptions import tutorial001 as mod
Expand All @@ -16,7 +17,11 @@ def test_traceback_rich():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" not in result.stderr

Expand All @@ -26,16 +31,18 @@ def test_traceback_rich():
assert "name = 'morty'" in result.stderr


def test_standard_traceback_env_var():
@pytest.mark.parametrize(
"env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
)
def test_standard_traceback_env_var(env_var: str):
file_path = Path(mod.__file__)
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": "1"},
env={**os.environ, env_var: "1"},
)
assert "return get_command(self)(*args, **kwargs)" in result.stderr

assert "typer.run(main)" in result.stderr
assert "print(name + 3)" in result.stderr
assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr
Expand Down
14 changes: 11 additions & 3 deletions tests/test_tutorial/test_exceptions/test_tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from pathlib import Path

import pytest
from typer.testing import CliRunner

from docs_src.exceptions import tutorial002 as mod
Expand All @@ -16,7 +17,11 @@ def test_traceback_rich():
[sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" not in result.stderr

Expand All @@ -26,13 +31,16 @@ def test_traceback_rich():
assert "name = 'morty'" not in result.stderr


def test_standard_traceback_env_var():
@pytest.mark.parametrize(
"env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
)
def test_standard_traceback_env_var(env_var: str):
file_path = Path(mod.__file__)
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": "1"},
env={**os.environ, env_var: "1"},
)
assert "return get_command(self)(*args, **kwargs)" in result.stderr

Expand Down
6 changes: 5 additions & 1 deletion tests/test_tutorial/test_exceptions/test_tutorial003.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def test_traceback_rich_pretty_short_disable():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" not in result.stderr

Expand Down
6 changes: 5 additions & 1 deletion tests/test_tutorial/test_exceptions/test_tutorial004.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def test_rich_pretty_exceptions_disable():
[sys.executable, "-m", "coverage", "run", str(file_path)],
capture_output=True,
encoding="utf-8",
env={**os.environ, "_TYPER_STANDARD_TRACEBACK": ""},
env={
**os.environ,
"TYPER_STANDARD_TRACEBACK": "",
"_TYPER_STANDARD_TRACEBACK": "",
},
)
assert "return get_command(self)(*args, **kwargs)" in result.stderr

Expand Down
4 changes: 3 additions & 1 deletion typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def except_hook(
exception_config: Union[DeveloperExceptionConfig, None] = getattr(
exc_value, _typer_developer_exception_attr_name, None
)
standard_traceback = os.getenv("_TYPER_STANDARD_TRACEBACK")
standard_traceback = os.getenv(
"TYPER_STANDARD_TRACEBACK", os.getenv("_TYPER_STANDARD_TRACEBACK")
)
if (
standard_traceback
or not exception_config
Expand Down
Loading