Pytest Loguru
Maintained. Last release 3 weeks ago, commits in 4 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install pytest-logurupytest-loguru
A pytest plugin to add support for loguru to pytest's caplog fixture.
You can install it from pypi with:
pip install pytest-loguru
and from conda-forge with:
conda install -c conda-forge pytest-loguru
Usage
Once installed, the plugin is registered automatically through pytest's
pytest11 entry point, so no import or configuration is needed. Messages
logged with loguru show up in caplog just like standard logging records,
and caplog.at_level / caplog.set_level filter them as usual:
import logging
from loguru import logger
def test_logs(caplog):
logger.warning("something happened")
assert "something happened" in caplog.text
def test_levels(caplog):
with caplog.at_level(logging.ERROR):
logger.info("ignored")
logger.error("kept")
assert caplog.messages == ["kept"]
Loguru records also reach pytest's other log handlers, in every test
whether or not it requests caplog: they appear under "Captured log call"
when a test fails, and in the live log when log_cli is enabled. Each
handler's level (log_level, log_cli_level) filters them as it does
standard records. Loguru's own sinks, such as the default stderr
one, are left alone.