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

Function test_log_file_ini

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

Source from the content-addressed store, hash-verified

775
776
777def test_log_file_ini(pytester: Pytester) -> None:
778 log_file = str(pytester.path.joinpath("pytest.log"))
779
780 pytester.makeini(
781 f"""
782 [pytest]
783 log_file={log_file}
784 log_file_level=WARNING
785 """
786 )
787 pytester.makepyfile(
788 """
789 import pytest
790 import logging
791 def test_log_file(request):
792 plugin = request.config.pluginmanager.getplugin('logging-plugin')
793 assert plugin.log_file_handler.level == logging.WARNING
794 logging.getLogger('catchlog').info("This log message won't be shown")
795 logging.getLogger('catchlog').warning("This log message will be shown")
796 print('PASSED')
797 """
798 )
799
800 result = pytester.runpytest("-s")
801
802 # fnmatch_lines does an assertion internally
803 result.stdout.fnmatch_lines(["test_log_file_ini.py PASSED"])
804
805 # make sure that we get a '0' exit code for the testsuite
806 assert result.ret == 0
807 assert os.path.isfile(log_file)
808 with open(log_file, encoding="utf-8") as rfh:
809 contents = rfh.read()
810 assert "This log message will be shown" in contents
811 assert "This log message won't be shown" not in contents
812
813
814def test_log_file_mode_ini(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected