MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_exceptions

Function test_exceptions

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

safereprFunction · 0.90
BrokenReprClass · 0.85
BrokenReprExceptionClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected