pytest-catchlog icon indicating copy to clipboard operation
pytest-catchlog copied to clipboard

Live logs (-s / --capture=no)

Open abusalimov opened this issue 9 years ago • 2 comments

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

abusalimov avatar Nov 20 '15 15:11 abusalimov

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.

The-Compiler avatar Nov 24 '15 11:11 The-Compiler

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:

abusalimov avatar Nov 24 '15 12:11 abusalimov