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

Function test_unraisable_in_setup

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

Source from the content-addressed store, hash-verified

42
43@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
44def test_unraisable_in_setup(pytester: Pytester) -> None:
45 pytester.makepyfile(
46 test_it="""
47 import pytest
48
49 class BrokenDel:
50 def __del__(self):
51 raise ValueError("del is broken")
52
53 @pytest.fixture
54 def broken_del():
55 obj = BrokenDel()
56 del obj
57
58 def test_it(broken_del): pass
59 def test_2(): pass
60 """
61 )
62 result = pytester.runpytest()
63 assert result.ret == 0
64 assert result.parseoutcomes() == {"passed": 2, "warnings": 1}
65 result.stdout.fnmatch_lines(
66 [
67 "*= warnings summary =*",
68 "test_it.py::test_it",
69 " * PytestUnraisableExceptionWarning: Exception ignored in: <function BrokenDel.__del__ at *>",
70 " ",
71 " Traceback (most recent call last):",
72 " ValueError: del is broken",
73 " ",
74 " warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))",
75 ]
76 )
77
78
79@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")

Callers

nothing calls this directly

Calls 4

parseoutcomesMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected