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

Function test_unraisable_collection_failure

testing/test_unraisableexception.py:193–218  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

191
192
193def test_unraisable_collection_failure(pytester: Pytester) -> None:
194 pytester.makepyfile(
195 test_it=f"""
196 class BrokenDel:
197 def __del__(self):
198 raise ValueError("del is broken")
199
200 def test_it():
201 obj = BrokenDel()
202 del obj
203 {"import gc; gc.collect()" * PYPY}
204
205 def test_2(): pass
206 """
207 )
208
209 class MyError(BaseException):
210 pass
211
212 with mock.patch("traceback.format_exception", side_effect=MyError):
213 result = pytester.runpytest()
214 assert result.ret == 1
215 result.assert_outcomes(passed=1, failed=1)
216 result.stdout.fnmatch_lines(
217 ["E RuntimeError: Failed to process unraisable exception"]
218 )
219
220
221def _set_gc_state(enabled: bool) -> bool:

Callers

nothing calls this directly

Calls 5

patchMethod · 0.80
assert_outcomesMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected