Capturing log messages

Capture log messages during test execution, appending them to the error reports of failed tests.

This plugin implements startTestRun(), startTest(), stopTest(), setTestOutcome(), and outcomeDetail() to set up a logging configuration that captures log messages during test execution, and appends them to error reports for tests that fail or raise exceptions.

Configuration [log-capture]

always-on
Default :False
Type :boolean
clear-handlers
Default :False
Type :boolean
date-format
Default :None
Type :str
filter
Default :[‘-nose’]
Type :list
format
Default :%(name)s: %(levelname)s: %(message)s
Type :str
log-level
Default :NOTSET
Type :str

Sample configuration

The default configuration is equivalent to including the following in a unittest.cfg file.

[log-capture]
always-on = False
clear-handlers = False
date-format = None
filter = -nose
format = %(name)s: %(levelname)s: %(message)s
log-level = NOTSET

Command-line options

--log-capture DEFAULT

Enable log capture

Plugin class reference: LogCapture

class nose2.plugins.logcapture.LogCapture[source]

Capture log messages during test execution

outcomeDetail(event)[source]

Append captured log messages to event.extraDetail

setTestOutcome(event)[source]

Store captured log messages in event.metadata

startTest(event)[source]

Set up handler for new test

startTestRun(event)[source]

Set up logging handler

stopTest(event)[source]

Clear captured messages, ready for next test