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

Function test_live_logs_unknown_sections

testing/logging/test_reporting.py:355–416  ·  view source on GitHub ↗

Check that with live logging enable we are printing the correct headers during start/setup/call/teardown/finish.

(
    pytester: Pytester, request: FixtureRequest
)

Source from the content-addressed store, hash-verified

353
354
355def test_live_logs_unknown_sections(
356 pytester: Pytester, request: FixtureRequest
357) -> None:
358 """Check that with live logging enable we are printing the correct headers during
359 start/setup/call/teardown/finish."""
360 filename = request.node.name + ".py"
361 pytester.makeconftest(
362 """
363 import pytest
364 import logging
365
366 def pytest_runtest_protocol(item, nextitem):
367 logging.warning('Unknown Section!')
368
369 def pytest_runtest_logstart():
370 logging.warning('>>>>> START >>>>>')
371
372 def pytest_runtest_logfinish():
373 logging.warning('<<<<< END <<<<<<<')
374 """
375 )
376
377 pytester.makepyfile(
378 """
379 import pytest
380 import logging
381
382 @pytest.fixture
383 def fix(request):
384 logging.warning("log message from setup of {}".format(request.node.name))
385 yield
386 logging.warning("log message from teardown of {}".format(request.node.name))
387
388 def test_log_1(fix):
389 logging.warning("log message from test_log_1")
390
391 """
392 )
393 pytester.makeini(
394 """
395 [pytest]
396 log_cli=true
397 """
398 )
399
400 result = pytester.runpytest()
401 result.stdout.fnmatch_lines(
402 [
403 "*WARNING*Unknown Section*",
404 f"{filename}::test_log_1 ",
405 "*WARNING* >>>>> START >>>>>*",
406 "*-- live log setup --*",
407 "*WARNING*log message from setup of test_log_1*",
408 "*-- live log call --*",
409 "*WARNING*log message from test_log_1*",
410 "PASSED *100%*",
411 "*-- live log teardown --*",
412 "*WARNING*log message from teardown of test_log_1*",

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
makeconftestMethod · 0.45
makepyfileMethod · 0.45
makeiniMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected