File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -62,5 +62,26 @@ def test_qtlog_fixture(qtlog):
62
62
(QtWarningMsg , 'this is a WARNING message ' ),
63
63
(QtCriticalMsg , 'this is a CRITICAL message ' ),
64
64
]
65
+ # `messages` attribute is read-only
65
66
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*' )
Original file line number Diff line number Diff line change @@ -517,4 +517,7 @@ def get_msg_name(cls, msg_type):
517
517
@pytest .fixture
518
518
def qtlog (request ):
519
519
"""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 ()
You can’t perform that action at this time.
0 commit comments