Logcapture: capture logging during tests

This plugin captures logging statements issued during test execution. When an error or failure occurs, the captured log messages are attached to the running test in the test.capturedLogging attribute, and displayed with the error failure output. It is enabled by default but can be turned off with the option --nologcapture.

You can filter captured logging statements with the --logging-filter option. If set, it specifies which logger(s) will be captured; loggers that do not match will be passed. Example: specifying --logging-filter=sqlalchemy,myapp will ensure that only statements logged via sqlalchemy.engine, myapp or myapp.foo.bar logger will be logged.

You can remove other installed logging handlers with the --logging-clear-handlers option.

Options

--nologcapture

Disable logging capture plugin. Logging configurtion will be left intact. [NOSE_NOLOGCAPTURE]

--logging-format=FORMAT

Specify custom format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGFORMAT]

--logging-datefmt=FORMAT

Specify custom date/time format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGDATEFMT]

--logging-filter=FILTER

Specify which statements to filter in/out. By default, everything is captured. If the output is too verbose, use this option to filter out needless output. Example: filter=foo will capture statements issued ONLY to foo or foo.what.ever.sub but not foobar or other logger. Specify multiple loggers with comma: filter=foo,bar,baz. If any logger name is prefixed with a minus, eg filter=-foo, it will be excluded rather than included. Default: exclude logging messages from nose itself (-nose). [NOSE_LOGFILTER]

--logging-clear-handlers

Clear all other logging handlers

Plugin

class nose.plugins.logcapture.LogCapture

Bases: nose.plugins.base.Plugin

Log capture plugin. Enabled by default. Disable with –nologcapture. This plugin captures logging statements issued during test execution, appending any output captured to the error or failure output, should the test fail or raise an error.

afterTest(test)

Clear buffers after test.

beforeTest(test)

Clear buffers and handlers before test.

begin()

Set up logging handler before test run begins.

configure(options, conf)

Configure plugin.

formatError(test, err)

Add captured log messages to error output.

formatFailure(test, err)

Add captured log messages to failure output.

options(parser, env)

Register commandline options.

Source

Table Of Contents

Previous topic

Isolate: protect tests from (some) side-effects

Next topic

Multiprocess: parallel testing

This Page