Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pytestqt/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ def _import_module(module_name):
self.Qt = QtCore.Qt
self.QEvent = QtCore.QEvent

# qInfo is not exposed in PyQt5 and PySide2 bindings (#225)
# qInfo is not exposed in PyQt5 and PySide2 bindings (#232)
assert not hasattr(
QtCore, "qInfo"
) # lets break hard so we know when qInfo gets exposed
self.qInfo = None
if hasattr(QtCore, "QMessageLogger"):
self.qInfo = lambda msg: QtCore.QMessageLogger().info(msg)
self.qDebug = QtCore.qDebug
self.qWarning = QtCore.qWarning
self.qCritical = QtCore.qCritical
Expand Down
25 changes: 22 additions & 3 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_types():
res.stdout.fnmatch_lines(
[
"*-- Captured Qt messages --*",
# qInfo is not exposed by the bindings yet (#225)
# qInfo is not exposed by the bindings yet (#232)
# '*QtInfoMsg: this is an INFO message*',
"*QtDebugMsg: this is a DEBUG message*",
"*QtWarningMsg: this is a WARNING message*",
Expand All @@ -61,7 +61,7 @@ def test_types():
res.stdout.fnmatch_lines(
[
"*-- Captured stderr call --*",
# qInfo is not exposed by the bindings yet (#225)
# qInfo is not exposed by the bindings yet (#232)
# '*QtInfoMsg: this is an INFO message*',
# 'this is an INFO message*',
"this is a DEBUG message*",
Expand All @@ -71,11 +71,30 @@ def test_types():
)


def test_qinfo(qtlog):
"""Test INFO messages when we have means to do so. Should be temporary until bindings
catch up and expose qInfo (or at least QMessageLogger), then we should update
the other logging tests properly. #232
"""
if qt_api.pytest_qt_api.startswith("pyside"):
assert (
qt_api.qInfo is None
), "pyside does not expose qInfo. If it does, update this test."
return

if qt_api.pytest_qt_api.startswith("pyqt4"):
pytest.skip("qInfo and QtInfoMsg not supported in PyQt 4")

qt_api.qInfo("this is an INFO message")
records = [(m.type, m.message.strip()) for m in qtlog.records]
assert records == [(qt_api.QtInfoMsg, "this is an INFO message")]


def test_qtlog_fixture(qtlog):
"""
Test qtlog fixture.
"""
# qInfo is not exposed by the bindings yet (#225)
# qInfo is not exposed by the bindings yet (#232)
qt_api.qDebug("this is a DEBUG message")
qt_api.qWarning("this is a WARNING message")
qt_api.qCritical("this is a CRITICAL message")
Expand Down