示例工程 26-debugging-diagnostics

26-debugging-diagnostics/01-read-deep-traceback/test_read_deep_traceback.py

python · 0.7 KB

"""test_read_deep_traceback.py"""
 
from __future__ import annotations
 
import pytest
from read_deep_traceback import formatted, main
 
 
def test_chain_contains_all_causes() -> None:
    text = formatted()
    assert "KeyError: 'count'" in text
    assert "ValueError: missing count" in text
    assert "TypeError: compute failed" in text
    assert text.count("direct cause") == 2
 
 
def test_frames_are_present() -> None:
    text = formatted()
    assert "in load" in text
    assert "in compute" in text
 
 
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
    main()
    out = capsys.readouterr().out
    assert "TypeError: compute failed" in out
    assert "direct cause" in out