Merge pull request #4812 from mitzkia/logging_from_runtest_logreport
Logging: Make pytest_runtest_logreport() hook available for logging
This commit is contained in:
commit
5b35241470
|
@ -0,0 +1 @@
|
|||
Logging messages inside ``pytest_runtest_logreport()`` are now properly captured and displayed.
|
|
@ -567,6 +567,11 @@ class LoggingPlugin(object):
|
|||
with self._runtest_for(None, "finish"):
|
||||
yield
|
||||
|
||||
@pytest.hookimpl(hookwrapper=True)
|
||||
def pytest_runtest_logreport(self):
|
||||
with self._runtest_for(None, "logreport"):
|
||||
yield
|
||||
|
||||
@pytest.hookimpl(hookwrapper=True, tryfirst=True)
|
||||
def pytest_sessionfinish(self):
|
||||
with self.live_logs_context():
|
||||
|
|
|
@ -1004,6 +1004,40 @@ def test_log_in_hooks(testdir):
|
|||
assert "sessionfinish" in contents
|
||||
|
||||
|
||||
def test_log_in_runtest_logreport(testdir):
|
||||
log_file = testdir.tmpdir.join("pytest.log").strpath
|
||||
|
||||
testdir.makeini(
|
||||
"""
|
||||
[pytest]
|
||||
log_file={}
|
||||
log_file_level = INFO
|
||||
log_cli=true
|
||||
""".format(
|
||||
log_file
|
||||
)
|
||||
)
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def pytest_runtest_logreport(report):
|
||||
logger.info("logreport")
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_first():
|
||||
assert True
|
||||
"""
|
||||
)
|
||||
testdir.runpytest()
|
||||
with open(log_file) as rfh:
|
||||
contents = rfh.read()
|
||||
assert contents.count("logreport") == 3
|
||||
|
||||
|
||||
def test_log_set_path(testdir):
|
||||
report_dir_base = testdir.tmpdir.strpath
|
||||
|
||||
|
|
Loading…
Reference in New Issue