Coverage for tests / test_tutorial / test_exceptions / test_tutorial001.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
1import os 1abcdefg
2import subprocess 1abcdefg
3import sys 1abcdefg
4from pathlib import Path 1abcdefg
6import pytest 1abcdefg
7from typer.testing import CliRunner 1abcdefg
9from docs_src.exceptions import tutorial001_py310 as mod 1abcdefg
11runner = CliRunner() 1abcdefg
14def test_traceback_rich(): 1abcdefg
15 file_path = Path(mod.__file__) 1abcdefg
16 result = subprocess.run( 1abcdefg
17 [sys.executable, "-m", "coverage", "run", str(file_path)],
18 capture_output=True,
19 encoding="utf-8",
20 env={
21 **os.environ,
22 "TYPER_STANDARD_TRACEBACK": "",
23 "_TYPER_STANDARD_TRACEBACK": "",
24 },
25 )
26 assert "return get_command(self)(*args, **kwargs)" not in result.stderr 1abcdefg
28 assert "app()" not in result.stderr 1abcdefg
29 assert "print(name + 3)" in result.stderr 1abcdefg
30 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefg
31 assert "name = 'morty'" not in result.stderr 1abcdefg
34@pytest.mark.parametrize( 1abcdefg
35 "env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
36)
37def test_standard_traceback_env_var(env_var: str): 1abcdefg
38 file_path = Path(mod.__file__) 1abcdefg
39 result = subprocess.run( 1abcdefg
40 [sys.executable, "-m", "coverage", "run", str(file_path)],
41 capture_output=True,
42 encoding="utf-8",
43 env={**os.environ, env_var: "1"},
44 )
45 assert "return get_command(self)(*args, **kwargs)" in result.stderr 1abcdefg
47 assert "app()" in result.stderr 1abcdefg
48 assert "print(name + 3)" in result.stderr 1abcdefg
49 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefg
50 assert "name = 'morty'" not in result.stderr 1abcdefg
53def test_script(): 1abcdefg
54 result = subprocess.run( 1abcdefg
55 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
56 capture_output=True,
57 encoding="utf-8",
58 )
59 assert "Usage" in result.stdout 1abcdefg