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

Function test_log_set_path

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

Source from the content-addressed store, hash-verified

1027
1028
1029def test_log_set_path(pytester: Pytester) -> None:
1030 report_dir_base = str(pytester.path)
1031
1032 pytester.makeini(
1033 """
1034 [pytest]
1035 log_file_level = DEBUG
1036 log_cli=true
1037 """
1038 )
1039 pytester.makeconftest(
1040 """
1041 import os
1042 import pytest
1043 @pytest.hookimpl(hookwrapper=True, tryfirst=True)
1044 def pytest_runtest_setup(item):
1045 config = item.config
1046 logging_plugin = config.pluginmanager.get_plugin("logging-plugin")
1047 report_file = os.path.join({}, item._request.node.name)
1048 logging_plugin.set_log_path(report_file)
1049 yield
1050 """.format(
1051 repr(report_dir_base)
1052 )
1053 )
1054 pytester.makepyfile(
1055 """
1056 import logging
1057 logger = logging.getLogger("testcase-logger")
1058 def test_first():
1059 logger.info("message from test 1")
1060 assert True
1061
1062 def test_second():
1063 logger.debug("message from test 2")
1064 assert True
1065 """
1066 )
1067 pytester.runpytest()
1068 with open(os.path.join(report_dir_base, "test_first")) as rfh:
1069 content = rfh.read()
1070 assert "message from test 1" in content
1071
1072 with open(os.path.join(report_dir_base, "test_second")) as rfh:
1073 content = rfh.read()
1074 assert "message from test 2" in content
1075
1076
1077def test_colored_captured_log(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

makeiniMethod · 0.45
makeconftestMethod · 0.45
formatMethod · 0.45
makepyfileMethod · 0.45
runpytestMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected