From 23a62e952d628cb9d29eac07f78ab5d88c343ece Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 27 Oct 2016 14:49:35 +0200 Subject: [PATCH] another lineparser/utilcmds test revision * verify exception message in lineparser double open * check for hunter with `pytest.importorskip` * stricter exception checking in debug_trace test --- tests/unit/misc/test_lineparser.py | 3 ++- tests/unit/misc/test_utilcmds.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/unit/misc/test_lineparser.py b/tests/unit/misc/test_lineparser.py index 7b5710ece..3ea07a831 100644 --- a/tests/unit/misc/test_lineparser.py +++ b/tests/unit/misc/test_lineparser.py @@ -66,9 +66,10 @@ class TestBaseLineParser: mocker.patch('builtins.open', mock.mock_open()) with lineparser._open('r'): - with pytest.raises(IOError): + with pytest.raises(IOError) as excinfo: with lineparser._open('r'): pass + assert str(excinfo.value) == 'Refusing to double-open AppendLineParser.' def test_binary(self, mocker): """Test if _open and _write correctly handle binary files.""" diff --git a/tests/unit/misc/test_utilcmds.py b/tests/unit/misc/test_utilcmds.py index cbfb88f9c..1cdfed2f6 100644 --- a/tests/unit/misc/test_utilcmds.py +++ b/tests/unit/misc/test_utilcmds.py @@ -26,13 +26,6 @@ import pytest import signal import time -_hunter_available = False -try: - import hunter # pylint: disable=unused-import - _hunter_available = True -except ImportError: - pass - from qutebrowser.misc import utilcmds from qutebrowser.commands import cmdexc @@ -73,16 +66,22 @@ def test_debug_crash_segfault(): assert 'Segfault failed' in str(excinfo.value) -@pytest.mark.skipif(not _hunter_available, reason="hunter not available") def test_debug_trace(mocker): """Check if hunter.trace is properly called.""" + # but only if hunter is available + pytest.importorskip('hunter') hunter_mock = mocker.patch('qutebrowser.misc.utilcmds.hunter') utilcmds.debug_trace(1) assert hunter_mock.trace.assert_called_with(1) + def _mock_exception(): + """Side effect for testing debug_trace's reraise.""" + raise Exception('message') + hunter_mock.trace.side_effect = Exception - with pytest.raises(Exception): + with pytest.raises(CommandError) as excinfo: utilcmds.debug_trace() + assert str(excinfo.value) == 'Exception: message' def test_debug_trace_no_hunter(monkeypatch):