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

Function test_caplog_captures_despite_exception

testing/logging/test_fixture.py:241–268  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

239
240
241def test_caplog_captures_despite_exception(pytester: Pytester) -> None:
242 pytester.makepyfile(
243 """
244 import pytest
245 import logging
246 def test_log_level_override(request, caplog):
247 logger = logging.getLogger('catchlog')
248 plugin = request.config.pluginmanager.getplugin('logging-plugin')
249 assert plugin.log_level == logging.WARNING
250
251 logger.error("ERROR message " + "will be shown")
252
253 with caplog.at_level(logging.DEBUG, logger.name):
254 logger.debug("DEBUG message " + "won't be shown")
255 raise Exception()
256 """
257 )
258 pytester.makeini(
259 """
260 [pytest]
261 log_level=WARNING
262 """
263 )
264
265 result = pytester.runpytest()
266 result.stdout.fnmatch_lines(["*ERROR message will be shown*"])
267 result.stdout.no_fnmatch_line("*DEBUG message won't be shown*")
268 assert result.ret == 1
269
270
271def test_log_report_captures_according_to_config_option_upon_failure(

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
no_fnmatch_lineMethod · 0.80
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected