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

Function test_unhandled_thread_exception

testing/test_threadexception.py:12–42  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

10
11@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
12def test_unhandled_thread_exception(pytester: Pytester) -> None:
13 pytester.makepyfile(
14 test_it="""
15 import threading
16
17 def test_it():
18 def oops():
19 raise ValueError("Oops")
20
21 t = threading.Thread(target=oops, name="MyThread")
22 t.start()
23 t.join()
24
25 def test_2(): pass
26 """
27 )
28 result = pytester.runpytest()
29 assert result.ret == 0
30 assert result.parseoutcomes() == {"passed": 2, "warnings": 1}
31 result.stdout.fnmatch_lines(
32 [
33 "*= warnings summary =*",
34 "test_it.py::test_it",
35 " * PytestUnhandledThreadExceptionWarning: Exception in thread MyThread",
36 " ",
37 " Traceback (most recent call last):",
38 " ValueError: Oops",
39 " ",
40 " warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))",
41 ]
42 )
43
44
45@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")

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