5
5
from pytestqt .qt_compat import qt_api
6
6
7
7
8
+ # qInfo is not exposed by PySide6 < 6.8.2 (#225)
9
+ HAS_QINFO = qt_api .qInfo is not None
10
+
11
+
8
12
@pytest .mark .parametrize ("test_succeeds" , [True , False ])
9
13
@pytest .mark .parametrize ("qt_log" , [True , False ])
10
14
def test_basic_logging (testdir , test_succeeds , qt_log ):
@@ -14,7 +18,7 @@ def test_basic_logging(testdir, test_succeeds, qt_log):
14
18
:type testdir: _pytest.pytester.TmpTestdir
15
19
"""
16
20
testdir .makepyfile (
17
- """
21
+ f """
18
22
import sys
19
23
from pytestqt.qt_compat import qt_api
20
24
@@ -26,15 +30,13 @@ def print_msg(msg_type, context, message):
26
30
qt_api.QtCore.qInstallMessageHandler(print_msg)
27
31
28
32
def test_types():
29
- # qInfo is not exposed by the bindings yet (#225)
30
- # qt_api.qInfo('this is an INFO message')
33
+ if { HAS_QINFO } :
34
+ qt_api.qInfo('this is an INFO message')
31
35
qt_api.qDebug('this is a DEBUG message')
32
36
qt_api.qWarning('this is a WARNING message')
33
37
qt_api.qCritical('this is a CRITICAL message')
34
- assert {}
35
- """ .format (
36
- test_succeeds
37
- )
38
+ assert { test_succeeds }
39
+ """
38
40
)
39
41
res = testdir .runpytest (* (["--no-qt-log" ] if not qt_log else []))
40
42
if test_succeeds :
@@ -45,8 +47,7 @@ def test_types():
45
47
res .stdout .fnmatch_lines (
46
48
[
47
49
"*-- Captured Qt messages --*" ,
48
- # qInfo is not exposed by the bindings yet (#232)
49
- # '*QtInfoMsg: this is an INFO message*',
50
+ * (["*QtInfoMsg: this is an INFO message*" ] if HAS_QINFO else []),
50
51
"*QtDebugMsg: this is a DEBUG message*" ,
51
52
"*QtWarningMsg: this is a WARNING message*" ,
52
53
"*QtCriticalMsg: this is a CRITICAL message*" ,
@@ -56,47 +57,35 @@ def test_types():
56
57
res .stdout .fnmatch_lines (
57
58
[
58
59
"*-- Captured stderr call --*" ,
59
- # qInfo is not exposed by the bindings yet (#232)
60
- # '*QtInfoMsg: this is an INFO message*',
61
- # 'this is an INFO message*',
60
+ * (["this is an INFO message*" ] if HAS_QINFO else []),
62
61
"this is a DEBUG message*" ,
63
62
"this is a WARNING message*" ,
64
63
"this is a CRITICAL message*" ,
65
64
]
66
65
)
67
66
68
67
69
- def test_qinfo (qtlog ):
70
- """Test INFO messages when we have means to do so. Should be temporary until bindings
71
- catch up and expose qInfo (or at least QMessageLogger), then we should update
72
- the other logging tests properly. #232
73
- """
74
-
75
- if qt_api .is_pyside :
76
- assert (
77
- qt_api .qInfo is None
78
- ), "pyside6 does not expose qInfo. If it does, update this test."
79
- return
80
-
81
- qt_api .qInfo ("this is an INFO message" )
82
- records = [(m .type , m .message .strip ()) for m in qtlog .records ]
83
- assert records == [(qt_api .QtCore .QtMsgType .QtInfoMsg , "this is an INFO message" )]
84
-
85
-
86
68
def test_qtlog_fixture (qtlog ):
87
69
"""
88
70
Test qtlog fixture.
89
71
"""
90
- # qInfo is not exposed by the bindings yet (#232)
72
+ expected = []
73
+ if HAS_QINFO :
74
+ qt_api .qInfo ("this is an INFO message" )
75
+ expected .append ((qt_api .QtCore .QtMsgType .QtInfoMsg , "this is an INFO message" ))
76
+
91
77
qt_api .qDebug ("this is a DEBUG message" )
92
78
qt_api .qWarning ("this is a WARNING message" )
93
79
qt_api .qCritical ("this is a CRITICAL message" )
94
- records = [( m . type , m . message . strip ()) for m in qtlog . records ]
95
- assert records = = [
80
+
81
+ expected + = [
96
82
(qt_api .QtCore .QtMsgType .QtDebugMsg , "this is a DEBUG message" ),
97
83
(qt_api .QtCore .QtMsgType .QtWarningMsg , "this is a WARNING message" ),
98
84
(qt_api .QtCore .QtMsgType .QtCriticalMsg , "this is a CRITICAL message" ),
99
85
]
86
+
87
+ records = [(m .type , m .message .strip ()) for m in qtlog .records ]
88
+ assert records == expected
100
89
# `records` attribute is read-only
101
90
with pytest .raises (AttributeError ):
102
91
qtlog .records = []
0 commit comments