From aa4cb2927d054b11821715f5575be55d3d5aab15 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 7 Jun 2015 02:29:20 +0200 Subject: [PATCH] Fix TestHideQtWarning tests for pytest 1.4.0. pytest captures the Qt logging messages, so we can't use qWarning to test. --- tests/utils/test_log.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/utils/test_log.py b/tests/utils/test_log.py index a09a354ee..eadaa7470 100644 --- a/tests/utils/test_log.py +++ b/tests/utils/test_log.py @@ -27,7 +27,6 @@ import itertools import sys import pytest -from PyQt5.QtCore import qWarning from qutebrowser.utils import log @@ -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()