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

Function test_messages

testing/logging/test_fixture.py:250–268  ·  testing/logging/test_fixture.py::test_messages
(caplog: pytest.LogCaptureFixture)

Source from the content-addressed store, hash-verified

248
249
250def test_messages(caplog: pytest.LogCaptureFixture) -> None:
251 caplog.set_level(logging.INFO)
252 logger.info(class="st">"boo %s", class="st">"arg")
253 logger.info(class="st">"bar %s\nbaz %s", class="st">"arg1", class="st">"arg2")
254 assert class="st">"boo arg" == caplog.messages[0]
255 assert class="st">"bar arg1\nbaz arg2" == caplog.messages[1]
256 assert caplog.text.count(class="st">"\n") > len(caplog.messages)
257 assert len(caplog.text.splitlines()) > len(caplog.messages)
258
259 try:
260 raise Exception(class="st">"test")
261 except Exception:
262 logger.exception(class="st">"oops")
263
264 assert class="st">"oops" in caplog.text
265 assert class="st">"oops" in caplog.messages[-1]
266 class="cm"># Tracebacks are stored in the record and not added until the formatter or handler.
267 assert class="st">"Exception" in caplog.text
268 assert class="st">"Exception" not in caplog.messages[-1]
269
270
271def test_record_tuples(caplog: pytest.LogCaptureFixture) -> None:

Callers

nothing calls this directly

Calls 1

set_levelMethod · 0.80

Tested by

no test coverage detected