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

Function test_log_file_ini_level

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

Source from the content-addressed store, hash-verified

745
746
747def test_log_file_ini_level(pytester: Pytester) -> None:
748 log_file = str(pytester.path.joinpath("pytest.log"))
749
750 pytester.makeini(
751 """
752 [pytest]
753 log_file={}
754 log_file_level = INFO
755 """.format(
756 log_file
757 )
758 )
759 pytester.makepyfile(
760 """
761 import pytest
762 import logging
763 def test_log_file(request):
764 plugin = request.config.pluginmanager.getplugin('logging-plugin')
765 assert plugin.log_file_handler.level == logging.INFO
766 logging.getLogger('catchlog').debug("This log message won't be shown")
767 logging.getLogger('catchlog').info("This log message will be shown")
768 print('PASSED')
769 """
770 )
771
772 result = pytester.runpytest("-s")
773
774 # fnmatch_lines does an assertion internally
775 result.stdout.fnmatch_lines(["test_log_file_ini_level.py PASSED"])
776
777 # make sure that we get a '0' exit code for the testsuite
778 assert result.ret == 0
779 assert os.path.isfile(log_file)
780 with open(log_file) as rfh:
781 contents = rfh.read()
782 assert "This log message will be shown" in contents
783 assert "This log message won't be shown" not in contents
784
785
786def test_log_file_unicode(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