Skip to main content

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.

Metadata

Release files for pytest-logbook 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-logbook 1.0.1
File Size Uploaded Provenance
pytest-logbook-1.0.1.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-logbook 1.0.1
File Interpreter ABI Platform
pytest_logbook-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / pytest-logbook-1.0.1.tar.gz

Download URL pytest-logbook-1.0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a884ebe01bbe384289e9b60fe15b71610d19b40e4dd195177f4a82185b4a7924
BLAKE2b-256 checksum
How to use checksums
3b2ea1878aa6b9d6b3b1c2b55ecab42db4921f966ca75799254d170a475aadb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pytest_logbook-1.0.1-py3-none-any.whl

Download URL pytest_logbook-1.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
baf627cc691e3fa76a6f5280dcd9a61619938a91ba148d12f46bcca750ed87b8
BLAKE2b-256 checksum
How to use checksums
5ec2c00e12c79cae6b88f1880b67dbbcec9b06e7075f1eb944e7e5250f814252
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pytest-logbook 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page