Skip to main content

py.test plugin to capture logbook log messages

Project description

Capture and show logbook logging output during test runs.

This pytest plugin provides will capture log messages emitted by logbook and display them in their own section in the test report if the test fails. Additionally it provides a fixture which provides easy access to the log records emitted during the test which allows making assertions on emitted log message. The plugin also sets up logging redirection from the stdlib to go via logbook so any libraries which use stdlib logging will also be captured.

Installation

Install using pip:

pip install pytest-logbook

Log Capturing

Log capturing happens automatically once installed, including stdlib logging redirection:

def test_foo():
    logbook.info('hello')
    logging.info('world')
    assert 0
$ py.test test_foo.py
=========================== test session starts ============================
platform linux -- Python 3.4.3, pytest-2.8.2, py-1.4.30, pluggy-0.3.1
rootdir: /home/flub/Abilisoft/repos/pytest-logbook, inifile:
plugins: logbook-0.1.0
collected 1 items

test_foo.py F

================================= FAILURES =================================
_________________________________ test_foo _________________________________

    def test_foo():
        logbook.info('hello')
        logging.info('world')
>       assert 0
E       assert 0

test_foo.py:7: AssertionError
--------------------------- Logbook call records ---------------------------
[INFO] Generic: hello
[INFO] root: world
========================= 1 failed in 0.01 seconds =========================

Logs messages emitted during test setup and teardown are also captured individually. If setup fails you will see them in a “Logbook setup records” section and if teardown fails you will see the teardown log messages in a “Logbook teardown records” section.

Fixtures

Several fixtures are provided to access the captured log records.

loghandler

Access the logbook.TestHandler instance active during the test run. You can use it to inspect the emitted log records, see the full documentation for details on how to use this object. Only log records emitted during the actual test are recorded here, records emitted during test setup or teardown are recorded in the other fixtures.

loghandler_setup

Access the logbook.TestHandler instance active during the test setup.

loghandler_teardown

Access the logbook.TestHandler instance active during the test teardown.

Configuration

The plugin can be configured using options in the py.test configuration file in the standard [pytest] section.

logbook_stdlib

This configures whether the stdlib logging is redirected to logbook. Set it to either true (default) or false.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-logbook-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytest_logbook-1.0.0-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-logbook-1.0.0.tar.gz.

File metadata

File hashes

Hashes for pytest-logbook-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c351c18213a400f550ac97ba4aeee7813bc5333f9d60eacee5c01d6090444219
MD5 f7d96964be5181b2e0e0bb9f5431884f
BLAKE2b-256 95cdb4eb6082f27f7c05c830396f65585d515ca71c9121de2e40a017f3187315

See more details on using hashes here.

File details

Details for the file pytest_logbook-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_logbook-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c76be89912b77405081838107ac60d3dc34c5cf31f48479ba4d9edd24fbc6d82
MD5 eb1146898c506262f55082814226dec4
BLAKE2b-256 5f8fd114e0f44364dec329da9c036d9b284e4d6d688125d960ec9aea66099af3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page