Skip to content

Commit e35e333

Browse files
committed
Add qt_log_ignore mark
1 parent 32f3831 commit e35e333

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

pytestqt/_tests/test_logging.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,34 @@ def test4():
232232
'*3 failed, 1 passed*',
233233
]
234234
res.stdout.fnmatch_lines(lines)
235+
236+
237+
@pytest.mark.parametrize('mark_regex', ['WM_DESTROY.*sent', 'no-match', None])
238+
def test_logging_fails_ignore_mark(testdir, mark_regex):
239+
"""
240+
Test qt_log_ignore mark overrides config option.
241+
242+
:type testdir: _pytest.pytester.TmpTestdir
243+
"""
244+
testdir.makeini(
245+
"""
246+
[pytest]
247+
qt_log_level_fail = CRITICAL
248+
"""
249+
)
250+
if mark_regex:
251+
mark = '@pytest.mark.qt_log_ignore("{0}")'.format(mark_regex)
252+
else:
253+
mark = ''
254+
testdir.makepyfile(
255+
"""
256+
from pytestqt.qt_compat import qWarning, qCritical
257+
import pytest
258+
{mark}
259+
def test1():
260+
qCritical('WM_DESTROY was sent')
261+
""".format(mark=mark)
262+
)
263+
res = testdir.inline_run()
264+
passed = 1 if mark_regex == 'WM_DESTROY.*sent' else 0
265+
res.assertoutcome(passed=passed, failed=int(not passed))

pytestqt/plugin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ def pytest_configure(config):
593593
config.addinivalue_line(
594594
'markers',
595595
'qt_log_level_fail: overrides qt_log_level_fail ini option.')
596+
config.addinivalue_line(
597+
'markers',
598+
'qt_log_ignore: overrides qt_log_ignore ini option.')
596599

597600
if config.getoption('qt_log'):
598601
config.pluginmanager.register(QtLoggingPlugin(config), '_qt_logging')
@@ -623,8 +626,12 @@ def __init__(self, config):
623626
self.config = config
624627

625628
def pytest_runtest_setup(self, item):
626-
item.qt_log_capture = _QtMessageCapture(
627-
item.config.getini('qt_log_ignore'))
629+
m = item.get_marker('qt_log_ignore')
630+
if m:
631+
ignore_regexes = m.args
632+
else:
633+
ignore_regexes = self.config.getini('qt_log_ignore')
634+
item.qt_log_capture = _QtMessageCapture(ignore_regexes)
628635
previous_handler = qInstallMsgHandler(item.qt_log_capture._handle)
629636
item.qt_previous_handler = previous_handler
630637

0 commit comments

Comments
 (0)