Pytest Loguru

0.4.0 · active · verified Thu Apr 16

pytest-loguru is a pytest plugin that integrates Loguru with pytest's `caplog` fixture. It replaces the default `caplog` fixture to seamlessly capture log messages emitted by Loguru, allowing for easy assertion in tests. The current version is 0.4.0, and it maintains a moderate release cadence with updates addressing compatibility and minor improvements.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to use the `caplog` fixture to capture messages emitted by Loguru. After installing `pytest-loguru`, the `caplog` fixture automatically intercepts Loguru messages, making them available for assertions via `caplog.text` and `caplog.records`.

from loguru import logger
import pytest

def test_loguru_messages_captured(caplog):
    logger.info("This is an info message from Loguru")
    logger.warning("This is a warning message from Loguru")
    assert "This is an info message from Loguru" in caplog.text
    assert "This is a warning message from Loguru" in caplog.text
    assert caplog.records[0].levelname == "INFO"
    assert caplog.records[1].levelname == "WARNING"

view raw JSON →