Skip to content

Commit b77ece1

Browse files
committed
Test new and legacy envs for setting standard tb
1 parent b04c314 commit b77ece1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/test_tutorial/test_exceptions/test_tutorial001.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from pathlib import Path
55

6+
import pytest
67
from typer.testing import CliRunner
78

89
from docs_src.exceptions import tutorial001 as mod
@@ -30,16 +31,18 @@ def test_traceback_rich():
3031
assert "name = 'morty'" in result.stderr
3132

3233

33-
def test_standard_traceback_env_var():
34+
@pytest.mark.parametrize(
35+
"env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
36+
)
37+
def test_standard_traceback_env_var(env_var: str):
3438
file_path = Path(mod.__file__)
3539
result = subprocess.run(
3640
[sys.executable, "-m", "coverage", "run", str(file_path)],
3741
capture_output=True,
3842
encoding="utf-8",
39-
env={**os.environ, "TYPER_STANDARD_TRACEBACK": "1"},
43+
env={**os.environ, env_var: "1"},
4044
)
4145
assert "return get_command(self)(*args, **kwargs)" in result.stderr
42-
4346
assert "typer.run(main)" in result.stderr
4447
assert "print(name + 3)" in result.stderr
4548
assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr

tests/test_tutorial/test_exceptions/test_tutorial002.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from pathlib import Path
55

6+
import pytest
67
from typer.testing import CliRunner
78

89
from docs_src.exceptions import tutorial002 as mod
@@ -30,13 +31,16 @@ def test_traceback_rich():
3031
assert "name = 'morty'" not in result.stderr
3132

3233

33-
def test_standard_traceback_env_var():
34+
@pytest.mark.parametrize(
35+
"env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
36+
)
37+
def test_standard_traceback_env_var(env_var: str):
3438
file_path = Path(mod.__file__)
3539
result = subprocess.run(
3640
[sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
3741
capture_output=True,
3842
encoding="utf-8",
39-
env={**os.environ, "TYPER_STANDARD_TRACEBACK": "1"},
43+
env={**os.environ, env_var: "1"},
4044
)
4145
assert "return get_command(self)(*args, **kwargs)" in result.stderr
4246

0 commit comments

Comments
 (0)