Coverage for tests / test_tutorial / test_exceptions / test_tutorial002.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1import os 1abcdefgh
2import subprocess 1abcdefgh
3import sys 1abcdefgh
4from pathlib import Path 1abcdefgh
6import pytest 1abcdefgh
7from typer.testing import CliRunner 1abcdefgh
9from docs_src.exceptions import tutorial002_py39 as mod 1abcdefgh
11runner = CliRunner() 1abcdefgh
14def test_traceback_rich(): 1abcdefgh
15 file_path = Path(mod.__file__) 1abcdefgh
16 result = subprocess.run( 1abcdefgh
17 [sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
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 1abcdefgh
28 assert "app()" not in result.stderr 1abcdefgh
29 assert "print(password + 3)" in result.stderr 1abcdefgh
30 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh
31 assert "name = 'morty'" not in result.stderr 1abcdefgh
34@pytest.mark.parametrize( 1abcdefgh
35 "env_var", ["TYPER_STANDARD_TRACEBACK", "_TYPER_STANDARD_TRACEBACK"]
36)
37def test_standard_traceback_env_var(env_var: str): 1abcdefgh
38 file_path = Path(mod.__file__) 1abcdefgh
39 result = subprocess.run( 1abcdefgh
40 [sys.executable, "-m", "coverage", "run", str(file_path), "secret"],
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 1abcdefgh
47 assert "app()" in result.stderr 1abcdefgh
48 assert "print(password + 3)" in result.stderr 1abcdefgh
49 assert 'TypeError: can only concatenate str (not "int") to str' in result.stderr 1abcdefgh
50 assert "name = 'morty'" not in result.stderr 1abcdefgh
53def test_script(): 1abcdefgh
54 result = subprocess.run( 1abcdefgh
55 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
56 capture_output=True,
57 encoding="utf-8",
58 )
59 assert "Usage" in result.stdout 1abcdefgh