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

Function test_log_file_mode_ini

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

Source from the content-addressed store, hash-verified

812
813
814def test_log_file_mode_ini(pytester: Pytester) -> None:
815 log_file = str(pytester.path.joinpath("pytest.log"))
816
817 pytester.makeini(
818 f"""
819 [pytest]
820 log_file={log_file}
821 log_file_mode=a
822 log_file_level=WARNING
823 """
824 )
825 pytester.makepyfile(
826 """
827 import pytest
828 import logging
829 def test_log_file(request):
830 plugin = request.config.pluginmanager.getplugin('logging-plugin')
831 assert plugin.log_file_handler.level == logging.WARNING
832 logging.getLogger('catchlog').info("This log message won't be shown")
833 logging.getLogger('catchlog').warning("This log message will be shown")
834 print('PASSED')
835 """
836 )
837
838 with open(log_file, mode="w", encoding="utf-8") as wfh:
839 wfh.write("A custom header\n")
840
841 result = pytester.runpytest("-s")
842
843 # fnmatch_lines does an assertion internally
844 result.stdout.fnmatch_lines(["test_log_file_mode_ini.py PASSED"])
845
846 assert result.ret == ExitCode.OK
847 assert os.path.isfile(log_file)
848 with open(log_file, encoding="utf-8") as rfh:
849 contents = rfh.read()
850 assert "A custom header" in contents
851 assert "This log message will be shown" in contents
852 assert "This log message won't be shown" not in contents
853
854
855def test_log_file_ini_level(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected