Skip to content

Commit 3f5ebf8

Browse files
committed
Add extend keyword argument to qt_log_ignore mark.
Fixes #99.
1 parent 9e05876 commit 3f5ebf8

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

pytestqt/logging.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def pytest_runtest_setup(self, item):
2424
return
2525
m = item.get_marker('qt_log_ignore')
2626
if m:
27-
ignore_regexes = m.args
27+
if m.kwargs.get('extend', False):
28+
config_regexes = self.config.getini('qt_log_ignore')
29+
ignore_regexes = config_regexes + list(m.args)
30+
else:
31+
ignore_regexes = m.args
2832
else:
2933
ignore_regexes = self.config.getini('qt_log_ignore')
3034
item.qt_log_capture = _QtMessageCapture(ignore_regexes)
@@ -277,4 +281,4 @@ def toterminal(self, out):
277281
self.fileloc.toterminal(out)
278282
for name, content, sep in self.sections:
279283
out.sep(sep, name)
280-
out.line(content)
284+
out.line(content)

tests/test_logging.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,34 @@ def test1():
340340
res.assertoutcome(passed=passed, failed=int(not passed))
341341

342342

343+
@pytest.mark.parametrize('message', ['match-global', 'match-mark'])
344+
def test_logging_mark_with_extend(testdir, message):
345+
"""
346+
Test qt_log_ignore mark with extend=True.
347+
348+
:type testdir: _pytest.pytester.TmpTestdir
349+
"""
350+
testdir.makeini(
351+
"""
352+
[pytest]
353+
qt_log_level_fail = CRITICAL
354+
qt_log_ignore = match-global
355+
"""
356+
)
357+
testdir.makepyfile(
358+
"""
359+
from pytestqt.qt_compat import qWarning, qCritical
360+
import pytest
361+
362+
@pytest.mark.qt_log_ignore('match-mark', extend=True)
363+
def test1():
364+
qCritical('{message}')
365+
""".format(message=message)
366+
)
367+
res = testdir.inline_run()
368+
res.assertoutcome(passed=1, failed=0)
369+
370+
343371
@pytest.mark.parametrize('apply_mark', [True, False])
344372
def test_logging_fails_ignore_mark_multiple(testdir, apply_mark):
345373
"""

0 commit comments

Comments
 (0)