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

Function test_log_file_ini_level

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

Source from the content-addressed store, hash-verified

853
854
855def test_log_file_ini_level(pytester: Pytester) -> None:
856 log_file = str(pytester.path.joinpath("pytest.log"))
857
858 pytester.makeini(
859 f"""
860 [pytest]
861 log_file={log_file}
862 log_file_level = INFO
863 """
864 )
865 pytester.makepyfile(
866 """
867 import pytest
868 import logging
869 def test_log_file(request):
870 plugin = request.config.pluginmanager.getplugin('logging-plugin')
871 assert plugin.log_file_handler.level == logging.INFO
872 logging.getLogger('catchlog').debug("This log message won't be shown")
873 logging.getLogger('catchlog').info("This log message will be shown")
874 print('PASSED')
875 """
876 )
877
878 result = pytester.runpytest("-s")
879
880 # fnmatch_lines does an assertion internally
881 result.stdout.fnmatch_lines(["test_log_file_ini_level.py PASSED"])
882
883 # make sure that we get a '0' exit code for the testsuite
884 assert result.ret == 0
885 assert os.path.isfile(log_file)
886 with open(log_file, encoding="utf-8") as rfh:
887 contents = rfh.read()
888 assert "This log message will be shown" in contents
889 assert "This log message won't be shown" not in contents
890
891
892def test_log_file_unicode(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