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

Function test_log_propagation_false

testing/logging/test_reporting.py:1258–1287  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

1256
1257
1258def test_log_propagation_false(pytester: Pytester) -> None:
1259 pytester.makepyfile(
1260 """
1261 import pytest
1262 import logging
1263
1264 logging.getLogger('foo').propagate = False
1265
1266 def test_log_file():
1267 logging.getLogger().warning("log goes to root logger")
1268 logging.getLogger('foo').warning("log goes to initially non-propagating logger")
1269 logging.getLogger('foo.bar').warning("log goes to initially non-propagating nested logger")
1270 assert False, "intentionally fail to trigger report logging output"
1271 """
1272 )
1273
1274 reprec = pytester.inline_run()
1275 reports = reprec.getfailures()
1276 assert len(reports) == 1
1277 report = reports[0]
1278 sections = list(report.get_sections("Captured log call"))
1279 assert len(sections) == 1
1280 assert sections[0][1] == "\n".join(
1281 [
1282 "WARNING root:test_log_propagation_false.py:7 log goes to root logger",
1283 "WARNING foo:test_log_propagation_false.py:8 log goes to initially non-propagating logger",
1284 "WARNING foo.bar:test_log_propagation_false.py:9 log goes to initially non-propagating nested logger",
1285 ]
1286 )
1287 assert not list(report.get_sections("Captured stderr call"))
1288
1289
1290def test_colored_ansi_esc_caplogtext(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

getfailuresMethod · 0.80
get_sectionsMethod · 0.80
joinMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected