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

Function test_log_file_cli_level

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

Source from the content-addressed store, hash-verified

732
733
734def test_log_file_cli_level(pytester: Pytester) -> None:
735 # Default log file level
736 pytester.makepyfile(
737 """
738 import pytest
739 import logging
740 def test_log_file(request):
741 plugin = request.config.pluginmanager.getplugin('logging-plugin')
742 assert plugin.log_file_handler.level == logging.INFO
743 logging.getLogger('catchlog').debug("This log message won't be shown")
744 logging.getLogger('catchlog').info("This log message will be shown")
745 print('PASSED')
746 """
747 )
748
749 log_file = str(pytester.path.joinpath("pytest.log"))
750
751 result = pytester.runpytest("-s", f"--log-file={log_file}", "--log-file-level=INFO")
752
753 # fnmatch_lines does an assertion internally
754 result.stdout.fnmatch_lines(["test_log_file_cli_level.py PASSED"])
755
756 # make sure that we get a '0' exit code for the testsuite
757 assert result.ret == 0
758 assert os.path.isfile(log_file)
759 with open(log_file, encoding="utf-8") as rfh:
760 contents = rfh.read()
761 assert "This log message will be shown" in contents
762 assert "This log message won't be shown" not in contents
763
764
765def test_log_level_not_changed_by_default(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected