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

Function test_log_file_ini

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

Source from the content-addressed store, hash-verified

706
707
708def test_log_file_ini(pytester: Pytester) -> None:
709 log_file = str(pytester.path.joinpath("pytest.log"))
710
711 pytester.makeini(
712 """
713 [pytest]
714 log_file={}
715 log_file_level=WARNING
716 """.format(
717 log_file
718 )
719 )
720 pytester.makepyfile(
721 """
722 import pytest
723 import logging
724 def test_log_file(request):
725 plugin = request.config.pluginmanager.getplugin('logging-plugin')
726 assert plugin.log_file_handler.level == logging.WARNING
727 logging.getLogger('catchlog').info("This log message won't be shown")
728 logging.getLogger('catchlog').warning("This log message will be shown")
729 print('PASSED')
730 """
731 )
732
733 result = pytester.runpytest("-s")
734
735 # fnmatch_lines does an assertion internally
736 result.stdout.fnmatch_lines(["test_log_file_ini.py PASSED"])
737
738 # make sure that we get a '0' exit code for the testsuite
739 assert result.ret == 0
740 assert os.path.isfile(log_file)
741 with open(log_file) as rfh:
742 contents = rfh.read()
743 assert "This log message will be shown" in contents
744 assert "This log message won't be shown" not in contents
745
746
747def test_log_file_ini_level(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected