Skip to content

Commit eaf09a7

Browse files
authored
Merge pull request #233 from nicoddemus/qinfo-tests
Implement quick test to avoid regression on INFO log messages (#232)
2 parents 72a4f22 + 2ec38df commit eaf09a7

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

pytestqt/qt_compat.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ def _import_module(module_name):
9797
self.Qt = QtCore.Qt
9898
self.QEvent = QtCore.QEvent
9999

100-
# qInfo is not exposed in PyQt5 and PySide2 bindings (#225)
100+
# qInfo is not exposed in PyQt5 and PySide2 bindings (#232)
101+
assert not hasattr(
102+
QtCore, "qInfo"
103+
) # lets break hard so we know when qInfo gets exposed
101104
self.qInfo = None
105+
if hasattr(QtCore, "QMessageLogger"):
106+
self.qInfo = lambda msg: QtCore.QMessageLogger().info(msg)
102107
self.qDebug = QtCore.qDebug
103108
self.qWarning = QtCore.qWarning
104109
self.qCritical = QtCore.qCritical

tests/test_logging.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_types():
5050
res.stdout.fnmatch_lines(
5151
[
5252
"*-- Captured Qt messages --*",
53-
# qInfo is not exposed by the bindings yet (#225)
53+
# qInfo is not exposed by the bindings yet (#232)
5454
# '*QtInfoMsg: this is an INFO message*',
5555
"*QtDebugMsg: this is a DEBUG message*",
5656
"*QtWarningMsg: this is a WARNING message*",
@@ -61,7 +61,7 @@ def test_types():
6161
res.stdout.fnmatch_lines(
6262
[
6363
"*-- Captured stderr call --*",
64-
# qInfo is not exposed by the bindings yet (#225)
64+
# qInfo is not exposed by the bindings yet (#232)
6565
# '*QtInfoMsg: this is an INFO message*',
6666
# 'this is an INFO message*',
6767
"this is a DEBUG message*",
@@ -71,11 +71,30 @@ def test_types():
7171
)
7272

7373

74+
def test_qinfo(qtlog):
75+
"""Test INFO messages when we have means to do so. Should be temporary until bindings
76+
catch up and expose qInfo (or at least QMessageLogger), then we should update
77+
the other logging tests properly. #232
78+
"""
79+
if qt_api.pytest_qt_api.startswith("pyside"):
80+
assert (
81+
qt_api.qInfo is None
82+
), "pyside does not expose qInfo. If it does, update this test."
83+
return
84+
85+
if qt_api.pytest_qt_api.startswith("pyqt4"):
86+
pytest.skip("qInfo and QtInfoMsg not supported in PyQt 4")
87+
88+
qt_api.qInfo("this is an INFO message")
89+
records = [(m.type, m.message.strip()) for m in qtlog.records]
90+
assert records == [(qt_api.QtInfoMsg, "this is an INFO message")]
91+
92+
7493
def test_qtlog_fixture(qtlog):
7594
"""
7695
Test qtlog fixture.
7796
"""
78-
# qInfo is not exposed by the bindings yet (#225)
97+
# qInfo is not exposed by the bindings yet (#232)
7998
qt_api.qDebug("this is a DEBUG message")
8099
qt_api.qWarning("this is a WARNING message")
81100
qt_api.qCritical("this is a CRITICAL message")

0 commit comments

Comments
 (0)