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

Method test_broken_repr

testing/test_session.py:107–137  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

105 assert passed == skipped == 0
106
107 def test_broken_repr(self, pytester: Pytester) -> None:
108 p = pytester.makepyfile(
109 """
110 import pytest
111
112 class reprexc(BaseException):
113 def __str__(self):
114 return "Ha Ha fooled you, I'm a broken repr()."
115
116 class BrokenRepr1(object):
117 foo=0
118 def __repr__(self):
119 raise reprexc
120
121 class TestBrokenClass(object):
122 def test_explicit_bad_repr(self):
123 t = BrokenRepr1()
124 with pytest.raises(BaseException, match="broken repr"):
125 repr(t)
126
127 def test_implicit_bad_repr1(self):
128 t = BrokenRepr1()
129 assert t.foo == 1
130
131 """
132 )
133 reprec = pytester.inline_run(p)
134 passed, skipped, failed = reprec.listoutcomes()
135 assert (len(passed), len(skipped), len(failed)) == (1, 0, 1)
136 out = failed[0].longrepr.reprcrash.message # type: ignore[union-attr]
137 assert out.find("<[reprexc() raised in repr()] BrokenRepr1") != -1
138
139 def test_broken_repr_with_showlocals_verbose(self, pytester: Pytester) -> None:
140 p = pytester.makepyfile(

Callers

nothing calls this directly

Calls 3

listoutcomesMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected