Source

pytest-capturelog /

Filename Size Date modified Message
55 B
212 B
1.0 KB
2.1 KB
5.7 KB
1.1 KB
1.3 KB

pytest-capturelog

py.test plugin to capture log messages

Usage

Log messages are captured by default and for each failed test will be shown in the same manner as captured stdout and stderr.

Running without options:

py.test test_capturelog.py

Shows failed tests like so:

-------------------------- Captured log ---------------------------
test_capturelog.py          26 INFO     text going to logger
------------------------- Captured stdout -------------------------
text going to stdout
------------------------- Captured stderr -------------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================

By default each captured log message shows the module, line number, log level and message. Showing the exact module and line number is useful for testing and debugging. If desired the log format and date format can be specified to anything that the logging module supports.

Running pytest specifying formatting options:

py.test --log-format="%(asctime)s %(levelname)s %(message)s" --log-date-format="%Y-%m-%d %H:%M:%S" test_capturelog.py

Shows failed tests like so:

-------------------------- Captured log ---------------------------
2010-04-10 14:48:44 INFO text going to logger
------------------------- Captured stdout -------------------------
text going to stdout
------------------------- Captured stderr -------------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================

Further it is possible to disable capturing of logs completely with:

py.test --nocapturelog test_capturelog.py

Shows failed tests in the normal manner as no logs were captured:

------------------------- Captured stdout -------------------------
text going to stdout
------------------------- Captured stderr -------------------------
text going to stderr
==================== 2 failed in 0.02 seconds =====================

Installation

With pip:

pip install pytest-capturelog

With easy install:

easy_install pytest-capturelog