| Total Complexity | 1 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import logging |
||
|
|
|||
| 2 | |||
| 3 | import pytest |
||
| 4 | from _pytest.logging import caplog as _caplog |
||
| 5 | from loguru import logger |
||
| 6 | |||
| 7 | |||
| 8 | # see: https://loguru.readthedocs.io/en/stable/resources/migration.html#making-things-work-with-pytest-and-caplog |
||
| 9 | @pytest.fixture |
||
| 10 | def caplog(_caplog): |
||
| 11 | class PropogateHandler(logging.Handler): |
||
| 12 | def emit(self, record): |
||
| 13 | logging.getLogger(record.name).handle(record) |
||
| 14 | |||
| 15 | handler_id = logger.add(PropogateHandler(), format="{message} {extra}") |
||
| 16 | yield _caplog |
||
| 17 | logger.remove(handler_id) |
||
| 18 | |||
| 19 | |||
| 20 | __all__ = ["caplog"] |
||
| 21 |