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

Function test_log_in_hooks

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

Source from the content-addressed store, hash-verified

957
958
959def test_log_in_hooks(pytester: Pytester) -> None:
960 log_file = str(pytester.path.joinpath("pytest.log"))
961
962 pytester.makeini(
963 """
964 [pytest]
965 log_file={}
966 log_file_level = INFO
967 log_cli=true
968 """.format(
969 log_file
970 )
971 )
972 pytester.makeconftest(
973 """
974 import logging
975
976 def pytest_runtestloop(session):
977 logging.info('runtestloop')
978
979 def pytest_sessionstart(session):
980 logging.info('sessionstart')
981
982 def pytest_sessionfinish(session, exitstatus):
983 logging.info('sessionfinish')
984 """
985 )
986 result = pytester.runpytest()
987 result.stdout.fnmatch_lines(["*sessionstart*", "*runtestloop*", "*sessionfinish*"])
988 with open(log_file) as rfh:
989 contents = rfh.read()
990 assert "sessionstart" in contents
991 assert "runtestloop" in contents
992 assert "sessionfinish" in contents
993
994
995def test_log_in_runtest_logreport(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 6

fnmatch_linesMethod · 0.80
makeiniMethod · 0.45
formatMethod · 0.45
makeconftestMethod · 0.45
runpytestMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected