Skip to content

Commit 9c414d3

Browse files
committed
Add qt_log_level_fail mark
1 parent 3e719fe commit 9c414d3

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

pytestqt/_tests/test_logging.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,28 @@ def test_4():
149149
])
150150
lines.append('*{0} passed*'.format(expect_passes))
151151
res.stdout.fnmatch_lines(lines)
152+
153+
154+
def test_logging_fails_tests_mark(testdir):
155+
"""
156+
Test mark overrides what's configured in the ini file.
157+
158+
:type testdir: _pytest.pytester.TmpTestdir
159+
"""
160+
testdir.makeini(
161+
"""
162+
[pytest]
163+
qt_log_level_fail = CRITICAL
164+
"""
165+
)
166+
testdir.makepyfile(
167+
"""
168+
from pytestqt.qt_compat import qWarning, qCritical, qDebug
169+
import pytest
170+
@pytest.mark.qt_log_level_fail('WARNING')
171+
def test_1():
172+
qWarning('message')
173+
"""
174+
)
175+
res = testdir.inline_run()
176+
res.assertoutcome(failed=1)

pytestqt/plugin.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ def pytest_configure(config):
435435
"qt_no_exception_capture: Disables pytest-qt's automatic exception "
436436
'capture for just one test item.')
437437

438+
config.addinivalue_line(
439+
'markers',
440+
'qt_log_level_fail: overrides qt_log_level_fail ini option.')
441+
438442
if config.getoption('qt_log'):
439443
config.pluginmanager.register(QtLoggingPlugin(config), '_qt_logging')
440444

@@ -476,7 +480,13 @@ def pytest_runtest_makereport(self, item, call):
476480
report = outcome.result
477481

478482
log_format = self.config.getoption('qt_log_format')
479-
log_fail_level = self.config.getini('qt_log_level_fail')
483+
484+
m = item.get_marker('qt_log_level_fail')
485+
if m:
486+
log_fail_level = m.args[0]
487+
else:
488+
log_fail_level = self.config.getini('qt_log_level_fail')
489+
assert log_fail_level in QtLoggingPlugin.LOG_FAIL_OPTIONS
480490

481491
if call.when == 'call':
482492

@@ -618,4 +628,4 @@ def toterminal(self, out):
618628
self.fileloc.toterminal(out)
619629
for name, content, sep in self.sections:
620630
out.sep(sep, name)
621-
out.line(content)
631+
out.line(content)

0 commit comments

Comments
 (0)