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

Function test_collection_logging_to_file

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

Source from the content-addressed store, hash-verified

919
920
921def test_collection_logging_to_file(pytester: Pytester) -> None:
922 log_file = str(pytester.path.joinpath("pytest.log"))
923
924 pytester.makeini(
925 """
926 [pytest]
927 log_file={}
928 log_file_level = INFO
929 """.format(
930 log_file
931 )
932 )
933
934 pytester.makepyfile(
935 """
936 import logging
937
938 logging.getLogger().info("Normal message")
939
940 def test_simple():
941 logging.getLogger().debug("debug message in test_simple")
942 logging.getLogger().info("info message in test_simple")
943 """
944 )
945
946 result = pytester.runpytest()
947
948 result.stdout.no_fnmatch_line("*--- live log collection ---*")
949
950 assert result.ret == 0
951 assert os.path.isfile(log_file)
952 with open(log_file, encoding="utf-8") as rfh:
953 contents = rfh.read()
954 assert "Normal message" in contents
955 assert "debug message in test_simple" not in contents
956 assert "info message in test_simple" in contents
957
958
959def test_log_in_hooks(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected