Wrap :class:`logging.Logger` with a StringIO() handler. yields a StringIO handle. Example:: >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio: ... ... ... sio.getvalue()
(logger, loglevel=logging.ERROR)
| 700 | |
| 701 | @contextmanager |
| 702 | def wrap_logger(logger, loglevel=logging.ERROR): |
| 703 | """Wrap :class:`logging.Logger` with a StringIO() handler. |
| 704 | yields a StringIO handle. |
| 705 | Example:: |
| 706 | >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio: |
| 707 | ... ... |
| 708 | ... sio.getvalue() |
| 709 | """ |
| 710 | old_handlers = get_logger_handlers(logger) |
| 711 | sio = WhateverIO() |
| 712 | siohandler = logging.StreamHandler(sio) |
| 713 | logger.handlers = [siohandler] |
| 714 | |
| 715 | try: |
| 716 | yield sio |
| 717 | finally: |
| 718 | logger.handlers = old_handlers |
| 719 | |
| 720 | |
| 721 | @contextmanager |
nothing calls this directly
no test coverage detected