Skip to content

Commit aa4cb29

Browse files
committed
Fix TestHideQtWarning tests for pytest 1.4.0.
pytest captures the Qt logging messages, so we can't use qWarning to test.
1 parent 2117b2a commit aa4cb29

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

tests/utils/test_log.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import sys
2828

2929
import pytest
30-
from PyQt5.QtCore import qWarning
3130

3231
from qutebrowser.utils import log
3332

@@ -230,33 +229,37 @@ class TestHideQtWarning:
230229

231230
"""Tests for hide_qt_warning/QtWarningFilter."""
232231

233-
def test_unfiltered(self, caplog):
232+
@pytest.fixture()
233+
def logger(self):
234+
return logging.getLogger('qt-tests')
235+
236+
def test_unfiltered(self, logger, caplog):
234237
"""Test a message which is not filtered."""
235238
with log.hide_qt_warning("World", logger='qt-tests'):
236239
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
237-
qWarning("Hello World")
240+
logger.warning("Hello World")
238241
assert len(caplog.records()) == 1
239242
record = caplog.records()[0]
240243
assert record.levelname == 'WARNING'
241244
assert record.message == "Hello World"
242245

243-
def test_filtered_exact(self, caplog):
246+
def test_filtered_exact(self, logger, caplog):
244247
"""Test a message which is filtered (exact match)."""
245248
with log.hide_qt_warning("Hello", logger='qt-tests'):
246249
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
247-
qWarning("Hello")
250+
logger.warning("Hello")
248251
assert not caplog.records()
249252

250-
def test_filtered_start(self, caplog):
253+
def test_filtered_start(self, logger, caplog):
251254
"""Test a message which is filtered (match at line start)."""
252255
with log.hide_qt_warning("Hello", logger='qt-tests'):
253256
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
254-
qWarning("Hello World")
257+
logger.warning("Hello World")
255258
assert not caplog.records()
256259

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

0 commit comments

Comments
 (0)