MCPcopy
hub / github.com/pytest-dev/pytest / test_exceptions

Function test_exceptions

testing/io/test_saferepr.py:40–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38
39
40def test_exceptions() -> None:
41 class BrokenRepr:
42 def __init__(self, ex):
43 self.ex = ex
44
45 def __repr__(self):
46 raise self.ex
47
48 class BrokenReprException(Exception):
49 __str__ = None # type: ignore[assignment]
50 __repr__ = None # type: ignore[assignment]
51
52 assert "Exception" in saferepr(BrokenRepr(Exception("broken")))
53 s = saferepr(BrokenReprException("really broken"))
54 assert "TypeError" in s
55 assert "TypeError" in saferepr(BrokenRepr("string"))
56
57 none = None
58 try:
59 none() # type: ignore[misc]
60 except BaseException as exc:
61 exp_exc = repr(exc)
62 obj = BrokenRepr(BrokenReprException("omg even worse"))
63 s2 = saferepr(obj)
64 assert s2 == (
65 f"<[unpresentable exception ({exp_exc!s}) raised in repr()] BrokenRepr object at 0x{id(obj):x}>"
66 )
67
68
69def test_baseexception():

Callers

nothing calls this directly

Calls 3

safereprFunction · 0.90
BrokenReprClass · 0.85
BrokenReprExceptionClass · 0.85

Tested by

no test coverage detected