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

Function test_log_file_cli

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected