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

Function test_log_file_cli

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

Source from the content-addressed store, hash-verified

630
631
632def test_log_file_cli(pytester: Pytester) -> None:
633 # Default log file level
634 pytester.makepyfile(
635 """
636 import pytest
637 import logging
638 def test_log_file(request):
639 plugin = request.config.pluginmanager.getplugin('logging-plugin')
640 assert plugin.log_file_handler.level == logging.WARNING
641 logging.getLogger('catchlog').info("This log message won't be shown")
642 logging.getLogger('catchlog').warning("This log message will be shown")
643 print('PASSED')
644 """
645 )
646
647 log_file = str(pytester.path.joinpath("pytest.log"))
648
649 result = pytester.runpytest(
650 "-s", f"--log-file={log_file}", "--log-file-level=WARNING"
651 )
652
653 # fnmatch_lines does an assertion internally
654 result.stdout.fnmatch_lines(["test_log_file_cli.py PASSED"])
655
656 # make sure that we get a '0' exit code for the testsuite
657 assert result.ret == 0
658 assert os.path.isfile(log_file)
659 with open(log_file) as rfh:
660 contents = rfh.read()
661 assert "This log message will be shown" in contents
662 assert "This log message won't be shown" not in contents
663
664
665def test_log_file_cli_level(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected