summaryrefslogtreecommitdiff
path: root/tests/unit/utils/test_log.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-11-18 17:50:21 +0100
committerFlorian Bruhin <me@the-compiler.org>2019-11-18 17:50:21 +0100
commitab52937ae1402bd9b45783b913a0a7f35a574ccc (patch)
treedc26cba1b181b85041802febdec447c4acb2d71e /tests/unit/utils/test_log.py
parenta733fa9fd0af5438057fc791f6bd78b8a75a8ef5 (diff)
downloadqutebrowser-ab52937ae1402bd9b45783b913a0a7f35a574ccc.tar.gz
qutebrowser-ab52937ae1402bd9b45783b913a0a7f35a574ccc.zip
Add a "werror" debug flag to turn warnings into errors
Diffstat (limited to 'tests/unit/utils/test_log.py')
-rw-r--r--tests/unit/utils/test_log.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py
index 5487483ae..3c3f93f80 100644
--- a/tests/unit/utils/test_log.py
+++ b/tests/unit/utils/test_log.py
@@ -196,18 +196,24 @@ class TestInitLog:
"""Tests for init_log."""
+ def _get_default_args(self):
+ return argparse.Namespace(debug=True, loglevel='debug', color=True,
+ loglines=10, logfilter="", force_color=False,
+ json_logging=False, debug_flags=set())
+
@pytest.fixture(autouse=True)
def setup(self, mocker):
- """Mock out qInstallMessageHandler."""
mocker.patch('qutebrowser.utils.log.QtCore.qInstallMessageHandler',
autospec=True)
+ yield
+ # Make sure logging is in a sensible default state
+ args = self._get_default_args()
+ log.init_log(args)
@pytest.fixture
def args(self):
"""Fixture providing an argparse namespace for init_log."""
- return argparse.Namespace(debug=True, loglevel='debug', color=True,
- loglines=10, logfilter="", force_color=False,
- json_logging=False)
+ return self._get_default_args()
def test_stderr_none(self, args):
"""Test init_log with sys.stderr = None."""
@@ -232,6 +238,22 @@ class TestInitLog:
assert filter_mock.called
assert filter_mock.call_args[0] == (expected_names, negated)
+ def test_python_warnings(self, args, caplog):
+ log.init_log(args)
+
+ with caplog.at_level(logging.WARNING):
+ warnings.warn("test warning", PendingDeprecationWarning)
+
+ expected = "PendingDeprecationWarning: test warning"
+ assert expected in caplog.records[0].message
+
+ def test_python_warnings_werror(self, args):
+ args.debug_flags = {'werror'}
+ log.init_log(args)
+
+ with pytest.raises(PendingDeprecationWarning):
+ warnings.warn("test warning", PendingDeprecationWarning)
+
class TestHideQtWarning: