Skip to content

Commit

Permalink
Fix TestHideQtWarning tests for pytest 1.4.0.
Browse files Browse the repository at this point in the history
pytest captures the Qt logging messages, so we can't use qWarning to test.
  • Loading branch information
The-Compiler committed Jun 7, 2015
1 parent 2117b2a commit aa4cb29
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/utils/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import sys

import pytest
from PyQt5.QtCore import qWarning

from qutebrowser.utils import log

Expand Down Expand Up @@ -230,33 +229,37 @@ class TestHideQtWarning:

"""Tests for hide_qt_warning/QtWarningFilter."""

def test_unfiltered(self, caplog):
@pytest.fixture()
def logger(self):
return logging.getLogger('qt-tests')

def test_unfiltered(self, logger, caplog):
"""Test a message which is not filtered."""
with log.hide_qt_warning("World", logger='qt-tests'):
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
qWarning("Hello World")
logger.warning("Hello World")
assert len(caplog.records()) == 1
record = caplog.records()[0]
assert record.levelname == 'WARNING'
assert record.message == "Hello World"

def test_filtered_exact(self, caplog):
def test_filtered_exact(self, logger, caplog):
"""Test a message which is filtered (exact match)."""
with log.hide_qt_warning("Hello", logger='qt-tests'):
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
qWarning("Hello")
logger.warning("Hello")
assert not caplog.records()

def test_filtered_start(self, caplog):
def test_filtered_start(self, logger, caplog):
"""Test a message which is filtered (match at line start)."""
with log.hide_qt_warning("Hello", logger='qt-tests'):
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
qWarning("Hello World")
logger.warning("Hello World")
assert not caplog.records()

def test_filtered_whitespace(self, caplog):
def test_filtered_whitespace(self, logger, caplog):
"""Test a message which is filtered (match with whitespace)."""
with log.hide_qt_warning("Hello", logger='qt-tests'):
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
qWarning(" Hello World ")
logger.warning(" Hello World ")
assert not caplog.records()

1 comment on commit aa4cb29

@The-Compiler
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, the commit message of course should say pytest-qt.

Please sign in to comment.