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

Function test_log_file_cli_level

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

Source from the content-addressed store, hash-verified

663
664
665def test_log_file_cli_level(pytester: Pytester) -> None:
666 # Default log file level
667 pytester.makepyfile(
668 """
669 import pytest
670 import logging
671 def test_log_file(request):
672 plugin = request.config.pluginmanager.getplugin('logging-plugin')
673 assert plugin.log_file_handler.level == logging.INFO
674 logging.getLogger('catchlog').debug("This log message won't be shown")
675 logging.getLogger('catchlog').info("This log message will be shown")
676 print('PASSED')
677 """
678 )
679
680 log_file = str(pytester.path.joinpath("pytest.log"))
681
682 result = pytester.runpytest("-s", f"--log-file={log_file}", "--log-file-level=INFO")
683
684 # fnmatch_lines does an assertion internally
685 result.stdout.fnmatch_lines(["test_log_file_cli_level.py PASSED"])
686
687 # make sure that we get a '0' exit code for the testsuite
688 assert result.ret == 0
689 assert os.path.isfile(log_file)
690 with open(log_file) as rfh:
691 contents = rfh.read()
692 assert "This log message will be shown" in contents
693 assert "This log message won't be shown" not in contents
694
695
696def test_log_level_not_changed_by_default(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected