pytest-catchlog
pytest-catchlog copied to clipboard
Live logs (-s / --capture=no)
Partially resolves #14 ("Integrate with --capture and -v options of pytest"), in a slightly more natural and efficient way than proposed in #20 ("Move pytest-logging functionality to pytest-catchlog.")
Note: this includes changes proposed in PR #24, DO NOT MERGE until #24 is accepted. Also this lacks a proper description in the README.
TODO
- [ ] README
- [ ]
record.message
not initialized, add tests
It seems this breaks using LogRecord.message
:
def test_abort_typeerror(question, qtbot, mocker, caplog):
"""Test Question.abort() with .emit() raising a TypeError."""
signal_mock = mocker.patch('qutebrowser.utils.usertypes.Question.aborted')
signal_mock.emit.side_effect = TypeError
with caplog.at_level(logging.ERROR, 'misc'):
question.abort()
> assert caplog.records[0].message == 'Error while aborting question'
E AttributeError: 'LogRecord' object has no attribute 'message'
It seems to work when I use the caplog-rec-handler
branch from #24.
It seems this breaks using
LogRecord.message
Interesting enough. LogRecord.message
is initialized by Formatter.format()
, i.e. lazily. It is probably broken since replacing StreamHandler
with simple RecordingHandler
, which doesn't use formatting at all.
I'm not sure whether it is right to rely on that some Handler calls format()
, but I guess, it would be better to add a workaround for this in pytest-catchlog.
I'll add a regression test for this, thank you! :+1: