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

Function test_log_file_mode_cli

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

Source from the content-addressed store, hash-verified

665
666
667def test_log_file_mode_cli(pytester: Pytester) -> None:
668 # Default log file level
669 pytester.makepyfile(
670 """
671 import pytest
672 import logging
673 def test_log_file(request):
674 plugin = request.config.pluginmanager.getplugin('logging-plugin')
675 assert plugin.log_file_handler.level == logging.WARNING
676 logging.getLogger('catchlog').info("This log message won't be shown")
677 logging.getLogger('catchlog').warning("This log message will be shown")
678 print('PASSED')
679 """
680 )
681
682 log_file = str(pytester.path.joinpath("pytest.log"))
683
684 with open(log_file, mode="w", encoding="utf-8") as wfh:
685 wfh.write("A custom header\n")
686
687 result = pytester.runpytest(
688 "-s",
689 f"--log-file={log_file}",
690 "--log-file-mode=a",
691 "--log-file-level=WARNING",
692 )
693
694 # fnmatch_lines does an assertion internally
695 result.stdout.fnmatch_lines(["test_log_file_mode_cli.py PASSED"])
696
697 # make sure that we get a '0' exit code for the testsuite
698 assert result.ret == 0
699 assert os.path.isfile(log_file)
700 with open(log_file, encoding="utf-8") as rfh:
701 contents = rfh.read()
702 assert "A custom header" in contents
703 assert "This log message will be shown" in contents
704 assert "This log message won't be shown" not in contents
705
706
707def test_log_file_mode_cli_invalid(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
writeMethod · 0.45
runpytestMethod · 0.45
isfileMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…