Files
superqt/tests/test_qmessage_handler.py
Talley Lambert 3c8b5bcf98 refactor: update pyproject and ci, add py3.11 test (#132)
* refactor: reorg repo

* fix: include pyi in manifest

* remove extra

* changes

* why no trigger

* fix needs

* include python 3.11

* remove cache

* add back license

* bump versions

* fix py37

* fix napari test

* remove timeout

* fix py37 test

* test: fix py311 tests

* change windows test
2022-11-08 20:32:47 -05:00

37 lines
1.1 KiB
Python

import logging
from qtpy import QtCore
from superqt import QMessageHandler
def test_message_handler():
with QMessageHandler() as mh:
QtCore.qDebug("debug")
QtCore.qWarning("warning")
QtCore.qCritical("critical")
assert len(mh.records) == 3
assert mh.records[0].level == logging.DEBUG
assert mh.records[1].level == logging.WARNING
assert mh.records[2].level == logging.CRITICAL
assert "3 records" in repr(mh)
def test_message_handler_with_logger(caplog):
logger = logging.getLogger("test_logger")
caplog.set_level(logging.DEBUG, logger="test_logger")
with QMessageHandler(logger):
QtCore.qDebug("debug")
QtCore.qWarning("warning")
QtCore.qCritical("critical")
assert len(caplog.records) == 3
assert caplog.records[0].message == "debug"
assert caplog.records[0].levelno == logging.DEBUG
assert caplog.records[1].message == "warning"
assert caplog.records[1].levelno == logging.WARNING
assert caplog.records[2].message == "critical"
assert caplog.records[2].levelno == logging.CRITICAL