Skip to content

Commit 1ebf18f

Browse files
committed
qtlog returns empty message lists with --qt-no-log option
1 parent 374dbeb commit 1ebf18f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

pytestqt/_tests/test_logging.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,26 @@ def test_qtlog_fixture(qtlog):
6262
(QtWarningMsg, 'this is a WARNING message '),
6363
(QtCriticalMsg, 'this is a CRITICAL message '),
6464
]
65+
# `messages` attribute is read-only
6566
with pytest.raises(AttributeError):
66-
qtlog.messages = []
67+
qtlog.messages = []
68+
69+
70+
def test_fixture_with_loggin_disabled(testdir):
71+
"""
72+
Test that qtlog fixture doesn't capture anything if logging is disabled
73+
in the command line.
74+
75+
:type testdir: _pytest.pytester.TmpTestdir
76+
"""
77+
testdir.makepyfile(
78+
"""
79+
from pytestqt.qt_compat import qWarning
80+
81+
def test_types(qtlog):
82+
qWarning('message')
83+
assert qtlog.messages == []
84+
"""
85+
)
86+
res = testdir.runpytest('--no-qt-log')
87+
res.stdout.fnmatch_lines('*1 passed*')

pytestqt/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,7 @@ def get_msg_name(cls, msg_type):
517517
@pytest.fixture
518518
def qtlog(request):
519519
"""Fixture that can access messages captured during testing"""
520-
return request._pyfuncitem.qt_log_capture
520+
if hasattr(request._pyfuncitem, 'qt_log_capture'):
521+
return request._pyfuncitem.qt_log_capture
522+
else:
523+
return _QtMessageCapture()

0 commit comments

Comments
 (0)