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

Function test_messages

testing/logging/test_fixture.py:108–126  ·  view source on GitHub ↗
(caplog)

Source from the content-addressed store, hash-verified

106
107
108def test_messages(caplog):
109 caplog.set_level(logging.INFO)
110 logger.info("boo %s", "arg")
111 logger.info("bar %s\nbaz %s", "arg1", "arg2")
112 assert "boo arg" == caplog.messages[0]
113 assert "bar arg1\nbaz arg2" == caplog.messages[1]
114 assert caplog.text.count("\n") > len(caplog.messages)
115 assert len(caplog.text.splitlines()) > len(caplog.messages)
116
117 try:
118 raise Exception("test")
119 except Exception:
120 logger.exception("oops")
121
122 assert "oops" in caplog.text
123 assert "oops" in caplog.messages[-1]
124 # Tracebacks are stored in the record and not added until the formatter or handler.
125 assert "Exception" in caplog.text
126 assert "Exception" not in caplog.messages[-1]
127
128
129def test_record_tuples(caplog):

Callers

nothing calls this directly

Calls 2

set_levelMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected