Skip to content

Extend log patterns #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ __pycache__
/.tox
.env*
.coverage
/.cache
/.venv
11 changes: 9 additions & 2 deletions pytestqt/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ def pytest_runtest_setup(self, item):
return
m = item.get_marker('qt_log_ignore')
if m:
ignore_regexes = m.args
if not set(m.kwargs).issubset(set(['extend'])):
raise ValueError("Invalid keyword arguments in {0!r} for "
"qt_log_ignore mark.".format(m.kwargs))
if m.kwargs.get('extend', False):
config_regexes = self.config.getini('qt_log_ignore')
ignore_regexes = config_regexes + list(m.args)
else:
ignore_regexes = m.args
else:
ignore_regexes = self.config.getini('qt_log_ignore')
item.qt_log_capture = _QtMessageCapture(ignore_regexes)
Expand Down Expand Up @@ -277,4 +284,4 @@ def toterminal(self, out):
self.fileloc.toterminal(out)
for name, content, sep in self.sections:
out.sep(sep, name)
out.line(content)
out.line(content)
65 changes: 61 additions & 4 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_logging_fails_tests_mark(testdir):
)
testdir.makepyfile(
"""
from pytestqt.qt_compat import qWarning, qCritical, qDebug
from pytestqt.qt_compat import qWarning
import pytest
@pytest.mark.qt_log_level_fail('WARNING')
def test_1():
Expand Down Expand Up @@ -265,7 +265,7 @@ def test_logging_fails_ignore(testdir):
)
testdir.makepyfile(
"""
from pytestqt.qt_compat import qWarning, qCritical
from pytestqt.qt_compat import qCritical
import pytest

def test1():
Expand Down Expand Up @@ -319,6 +319,7 @@ def test_logging_fails_ignore_mark(testdir, mark_regex):
"""
[pytest]
qt_log_level_fail = CRITICAL
qt_log_ignore = no-match
"""
)
if mark_regex:
Expand All @@ -327,7 +328,7 @@ def test_logging_fails_ignore_mark(testdir, mark_regex):
mark = ''
testdir.makepyfile(
"""
from pytestqt.qt_compat import qWarning, qCritical
from pytestqt.qt_compat import qCritical
import pytest
{mark}
def test1():
Expand All @@ -339,6 +340,62 @@ def test1():
res.assertoutcome(passed=passed, failed=int(not passed))


@pytest.mark.parametrize('message', ['match-global', 'match-mark'])
def test_logging_mark_with_extend(testdir, message):
"""
Test qt_log_ignore mark with extend=True.

:type testdir: _pytest.pytester.TmpTestdir
"""
testdir.makeini(
"""
[pytest]
qt_log_level_fail = CRITICAL
qt_log_ignore = match-global
"""
)
testdir.makepyfile(
"""
from pytestqt.qt_compat import qCritical
import pytest

@pytest.mark.qt_log_ignore('match-mark', extend=True)
def test1():
qCritical('{message}')
""".format(message=message)
)
res = testdir.inline_run()
res.assertoutcome(passed=1, failed=0)


def test_logging_mark_with_invalid_argument(testdir):
"""
Test qt_log_ignore mark with invalid keyword argument.

:type testdir: _pytest.pytester.TmpTestdir
"""
testdir.makepyfile(
"""
import pytest

@pytest.mark.qt_log_ignore('match-mark', does_not_exist=True)
def test1():
pass
"""
)
res = testdir.runpytest()
lines = [
'*= ERRORS =*',
'*_ ERROR at setup of test1 _*',
"*ValueError: Invalid keyword arguments in {'does_not_exist': True} "
"for qt_log_ignore mark.",

# summary
'*= 1 error in*',
]
res.stdout.fnmatch_lines(lines)


@pytest.mark.parametrize('apply_mark', [True, False])
def test_logging_fails_ignore_mark_multiple(testdir, apply_mark):
"""
Expand All @@ -352,7 +409,7 @@ def test_logging_fails_ignore_mark_multiple(testdir, apply_mark):
mark = ''
testdir.makepyfile(
"""
from pytestqt.qt_compat import qWarning, qCritical
from pytestqt.qt_compat import qCritical
import pytest
@pytest.mark.qt_log_level_fail('CRITICAL')
{mark}
Expand Down