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)
| 679 | |
| 680 | @contextmanager |
| 681 | def wrap_logger(logger, loglevel=logging.ERROR): |
| 682 | """Wrap :class:`logging.Logger` with a StringIO() handler. |
| 683 | yields a StringIO handle. |
| 684 | Example:: |
| 685 | >>> with conftest.wrap_logger(logger, loglevel=logging.DEBUG) as sio: |
| 686 | ... ... |
| 687 | ... sio.getvalue() |
| 688 | """ |
| 689 | old_handlers = get_logger_handlers(logger) |
| 690 | sio = WhateverIO() |
| 691 | siohandler = logging.StreamHandler(sio) |
| 692 | logger.handlers = [siohandler] |
| 693 | |
| 694 | try: |
| 695 | yield sio |
| 696 | finally: |
| 697 | logger.handlers = old_handlers |
| 698 | |
| 699 | |
| 700 | @contextmanager |
nothing calls this directly
no test coverage detected
searching dependent graphs…