diff --git a/tests/unit/browser/test_adblock.py b/tests/unit/browser/test_adblock.py index aaa36d20b..906ac5aba 100644 --- a/tests/unit/browser/test_adblock.py +++ b/tests/unit/browser/test_adblock.py @@ -366,7 +366,7 @@ def test_invalid_utf8(config_stub, download_stub, tmpdir, data_tmpdir, current_download.finished.emit() expected = (r"Failed to decode: " r"b'https://www.example.org/\xa0localhost") - assert caplog.records[-2].message.startswith(expected) + assert caplog.messages[-2].startswith(expected) else: current_download.successful = True current_download.finished.emit() @@ -391,7 +391,7 @@ def test_invalid_utf8_compiled(config_stub, config_tmpdir, data_tmpdir, host_blocker = adblock.HostBlocker() with caplog.at_level(logging.ERROR): host_blocker.read_hosts() - assert caplog.records[-1].message == "Failed to read host blocklist!" + assert caplog.messages[-1] == "Failed to read host blocklist!" def test_blocking_with_whitelist(config_stub, basedir, download_stub, diff --git a/tests/unit/browser/test_pdfjs.py b/tests/unit/browser/test_pdfjs.py index 768180e11..884ba159b 100644 --- a/tests/unit/browser/test_pdfjs.py +++ b/tests/unit/browser/test_pdfjs.py @@ -155,8 +155,8 @@ class TestResources: pdfjs.get_pdfjs_res_and_path('web/test') assert len(caplog.records) == 1 - rec = caplog.records[0] - assert rec.message == 'OSError while reading PDF.js file: Message' + msg = caplog.messages[0] + assert msg == 'OSError while reading PDF.js file: Message' @pytest.mark.parametrize('path, expected', [ @@ -204,8 +204,8 @@ def test_read_from_system_oserror(tmpdir, caplog): assert pdfjs._read_from_system(str(tmpdir), ['unreadable']) == expected assert len(caplog.records) == 1 - rec = caplog.records[0] - assert rec.message.startswith('OSError while reading PDF.js file:') + message = caplog.messages[0] + assert message.startswith('OSError while reading PDF.js file:') @pytest.mark.parametrize('available', [True, False]) diff --git a/tests/unit/browser/test_qutescheme.py b/tests/unit/browser/test_qutescheme.py index 64d525367..d8353d7ae 100644 --- a/tests/unit/browser/test_qutescheme.py +++ b/tests/unit/browser/test_qutescheme.py @@ -204,7 +204,7 @@ class TestPDFJSHandler: with pytest.raises(qutescheme.NotFoundError): qutescheme.data_for_url(QUrl('qute://pdfjs/no/file.html')) assert len(caplog.records) == 1 - assert (caplog.records[0].message == + assert (caplog.messages[0] == 'pdfjs resource requested but not found: /no/file.html') def test_viewer_page(self, data_tmpdir): diff --git a/tests/unit/browser/test_signalfilter.py b/tests/unit/browser/test_signalfilter.py index 957b85943..e98207f15 100644 --- a/tests/unit/browser/test_signalfilter.py +++ b/tests/unit/browser/test_signalfilter.py @@ -88,7 +88,7 @@ def test_logging(caplog, objects, tabbed_browser_stubs, index_of, verb): assert len(caplog.records) == 1 expected_msg = "{}: filtered_signal('foo') (tab {})".format(verb, index_of) - assert caplog.records[0].msg == expected_msg + assert caplog.messages[0] == expected_msg @pytest.mark.parametrize('index_of', [0, 1]) diff --git a/tests/unit/browser/webengine/test_spell.py b/tests/unit/browser/webengine/test_spell.py index 14b343df5..2fe6ad8ac 100644 --- a/tests/unit/browser/webengine/test_spell.py +++ b/tests/unit/browser/webengine/test_spell.py @@ -141,8 +141,7 @@ class TestInit: with caplog.at_level(logging.ERROR): spell.init() - record = caplog.records[0] - assert record.message == 'Failed to copy old dictionaries' + assert caplog.messages[0] == 'Failed to copy old dictionaries' def test_moving_existing_destdir(self, old_dict_dir, dict_dir, patch_new_qt): diff --git a/tests/unit/browser/webengine/test_webenginetab.py b/tests/unit/browser/webengine/test_webenginetab.py index 093ae85fa..50bbdf716 100644 --- a/tests/unit/browser/webengine/test_webenginetab.py +++ b/tests/unit/browser/webengine/test_webenginetab.py @@ -50,7 +50,7 @@ class TestWebengineScripts: webengine_scripts._inject_greasemonkey_scripts(scripts) assert len(caplog.records) == 1 - msg = caplog.records[0].message + msg = caplog.messages[0] assert "has invalid value for '@qute-js-world': Mars" in msg collection = webengine_scripts._widget.page().scripts().toList() assert not any(script.name().startswith('GM-') @@ -69,7 +69,7 @@ class TestWebengineScripts: webengine_scripts._inject_greasemonkey_scripts(scripts) assert len(caplog.records) == 1 - msg = caplog.records[0].message + msg = caplog.messages[0] assert "has invalid value for '@qute-js-world': " in msg assert "should be between 0 and" in msg collection = webengine_scripts._widget.page().scripts().toList() diff --git a/tests/unit/commands/test_cmdutils.py b/tests/unit/commands/test_cmdutils.py index 66233c052..fc68fa920 100644 --- a/tests/unit/commands/test_cmdutils.py +++ b/tests/unit/commands/test_cmdutils.py @@ -389,8 +389,7 @@ class TestArgument: # no docstring pass assert len(caplog.records) == 1 - msg = caplog.records[0].message - assert msg.endswith('test_cmdutils.py has no docstring') + assert caplog.messages[0].endswith('test_cmdutils.py has no docstring') def test_no_docstring_with_optimize(self, monkeypatch): """With -OO we'd get a warning on start, but no warning afterwards.""" diff --git a/tests/unit/commands/test_userscripts.py b/tests/unit/commands/test_userscripts.py index 1e4aadbdd..ff6b9a558 100644 --- a/tests/unit/commands/test_userscripts.py +++ b/tests/unit/commands/test_userscripts.py @@ -227,7 +227,7 @@ def test_temporary_files_failed_cleanup(caplog, qtbot, py_proc, runner): assert len(caplog.records) == 1 expected = "Failed to delete tempfile" - assert caplog.records[0].message.startswith(expected) + assert caplog.messages[0].startswith(expected) def test_unicode_error(caplog, qtbot, py_proc, runner): @@ -244,7 +244,7 @@ def test_unicode_error(caplog, qtbot, py_proc, runner): assert len(caplog.records) == 1 expected = "Invalid unicode in userscript output: " - assert caplog.records[0].message.startswith(expected) + assert caplog.messages[0].startswith(expected) @pytest.mark.fake_os('unknown') diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 6cef14130..6438f8b98 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -390,7 +390,7 @@ class TestConfig: assert blocker.args == ['tabs.show'] assert len(caplog.records) == 1 expected_message = 'Config option changed: tabs.show = never' - assert caplog.records[0].message == expected_message + assert caplog.messages[0] == expected_message def test_set_value_no_backend(self, monkeypatch, conf): """Make sure setting values when the backend is still unknown works.""" @@ -569,7 +569,7 @@ class TestConfig: conf.update_mutables() expected_log = '{} was mutated, updating'.format(option) - assert caplog.records[-2].message == expected_log + assert caplog.messages[-2] == expected_log else: with qtbot.assert_not_emitted(conf.changed): conf.update_mutables() @@ -791,7 +791,7 @@ def test_set_register_stylesheet(delete, stylesheet_param, update, qtbot, obj = StyleObj(stylesheet) config.set_register_stylesheet(obj, update=update) - assert caplog.records[-1].message == 'stylesheet for StyleObj: magenta' + assert caplog.messages[-1] == 'stylesheet for StyleObj: magenta' assert obj.rendered_stylesheet == 'magenta' diff --git a/tests/unit/keyinput/test_basekeyparser.py b/tests/unit/keyinput/test_basekeyparser.py index 135033ecd..25b470040 100644 --- a/tests/unit/keyinput/test_basekeyparser.py +++ b/tests/unit/keyinput/test_basekeyparser.py @@ -61,8 +61,7 @@ class TestDebugLog: def test_log(self, keyparser, caplog): keyparser._debug_log('foo') assert len(caplog.records) == 1 - record = caplog.records[0] - assert record.message == 'foo' + assert caplog.messages[0] == 'foo' def test_no_log(self, keyparser, caplog): keyparser.do_log = False diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 94021484a..7c13691e7 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -269,7 +269,7 @@ def test_failing_watch(qtbot, caplog, monkeypatch): assert blocker.args == ['bar'] message = 'Failed to watch path: {}'.format(editor._filename) - assert caplog.records[0].msg == message + assert caplog.messages[0] == message def test_failing_unwatch(qtbot, caplog, monkeypatch): @@ -285,7 +285,7 @@ def test_failing_unwatch(qtbot, caplog, monkeypatch): editor._proc.finished.emit(0, QProcess.NormalExit) message = 'Failed to unwatch paths: [{!r}]'.format(editor._filename) - assert caplog.records[-1].msg == message + assert caplog.messages[-1] == message @pytest.mark.parametrize('text, caret_position, result', [ diff --git a/tests/unit/misc/test_guiprocess.py b/tests/unit/misc/test_guiprocess.py index 329dc2ae0..cfedab9fe 100644 --- a/tests/unit/misc/test_guiprocess.py +++ b/tests/unit/misc/test_guiprocess.py @@ -171,9 +171,10 @@ def test_start_logging(fake_proc, caplog): args = ['arg', 'arg with spaces'] with caplog.at_level(logging.DEBUG): fake_proc.start(cmd, args) - msgs = [e.msg for e in caplog.records] - assert msgs == ["Starting process.", - "Executing: does_not_exist arg 'arg with spaces'"] + assert caplog.messages == [ + "Starting process.", + "Executing: does_not_exist arg 'arg with spaces'" + ] def test_error(qtbot, proc, caplog, message_mock): @@ -208,7 +209,7 @@ def test_exit_unsuccessful_output(qtbot, proc, caplog, py_proc, stream): print("test", file=sys.{}) sys.exit(1) """.format(stream))) - assert caplog.records[-1].msg == 'Process {}:\ntest'.format(stream) + assert caplog.messages[-1] == 'Process {}:\ntest'.format(stream) @pytest.mark.parametrize('stream', ['stdout', 'stderr']) diff --git a/tests/unit/misc/test_ipc.py b/tests/unit/misc/test_ipc.py index 73a9b4f12..ce4698c7d 100644 --- a/tests/unit/misc/test_ipc.py +++ b/tests/unit/misc/test_ipc.py @@ -338,7 +338,7 @@ class TestListen: with caplog.at_level(logging.ERROR): ipc_server.update_atime() - assert caplog.records[-1].msg == "In update_atime with no server path!" + assert caplog.messages[-1] == "In update_atime with no server path!" @pytest.mark.posix def test_atime_shutdown_typeerror(self, qtbot, ipc_server): @@ -381,22 +381,20 @@ class TestHandleConnection: def test_no_connection(self, ipc_server, caplog): ipc_server.handle_connection() - assert caplog.records[-1].message == "No new connection to handle." + assert caplog.messages[-1] == "No new connection to handle." def test_double_connection(self, qlocalsocket, ipc_server, caplog): ipc_server._socket = qlocalsocket ipc_server.handle_connection() msg = ("Got new connection but ignoring it because we're still " "handling another one") - assert any(rec.message.startswith(msg) for rec in caplog.records) + assert any(message.startswith(msg) for message in caplog.messages) def test_disconnected_immediately(self, ipc_server, caplog): socket = FakeSocket(state=QLocalSocket.UnconnectedState) ipc_server._server = FakeServer(socket) ipc_server.handle_connection() - msg = "Socket was disconnected immediately." - all_msgs = [r.message for r in caplog.records] - assert msg in all_msgs + assert "Socket was disconnected immediately." in caplog.messages def test_error_immediately(self, ipc_server, caplog): socket = FakeSocket(error=QLocalSocket.ConnectionError) @@ -406,9 +404,7 @@ class TestHandleConnection: r"connection: Error string \(error 7\)"): ipc_server.handle_connection() - msg = "We got an error immediately." - all_msgs = [r.message for r in caplog.records] - assert msg in all_msgs + assert "We got an error immediately." in caplog.messages def test_read_line_immediately(self, qtbot, ipc_server, caplog): data = ('{{"args": ["foo"], "target_arg": "tab", ' @@ -421,8 +417,7 @@ class TestHandleConnection: ipc_server.handle_connection() assert blocker.args == [['foo'], 'tab', ''] - all_msgs = [r.message for r in caplog.records] - assert "We can read a line immediately." in all_msgs + assert "We can read a line immediately." in caplog.messages @pytest.fixture @@ -475,9 +470,9 @@ def test_invalid_data(qtbot, ipc_server, connected_socket, caplog, data, msg): with qtbot.waitSignals(signals, order='strict'): connected_socket.write(data) - messages = [r.message for r in caplog.records] - assert messages[-1].startswith('Ignoring invalid IPC data from socket ') - assert messages[-2].startswith(msg) + invalid_msg = 'Ignoring invalid IPC data from socket ' + assert caplog.messages[-1].startswith(invalid_msg) + assert caplog.messages[-2].startswith(msg) def test_multiline(qtbot, ipc_server, connected_socket): @@ -504,8 +499,7 @@ class TestSendToRunningInstance: def test_no_server(self, caplog): sent = ipc.send_to_running_instance('qute-test', [], None) assert not sent - msg = caplog.records[-1].message - assert msg == "No existing instance present (error 2)" + assert caplog.messages[-1] == "No existing instance present (error 2)" @pytest.mark.parametrize('has_cwd', [True, False]) @pytest.mark.linux(reason="Causes random trouble on Windows and macOS") @@ -571,7 +565,7 @@ def test_timeout(qtbot, caplog, qlocalsocket, ipc_server): with qtbot.waitSignal(qlocalsocket.disconnected, timeout=5000): pass - assert caplog.records[-1].message.startswith("IPC connection timed out") + assert caplog.messages[-1].startswith("IPC connection timed out") def test_ipcserver_socket_none_readyread(ipc_server, caplog): @@ -580,7 +574,7 @@ def test_ipcserver_socket_none_readyread(ipc_server, caplog): with caplog.at_level(logging.WARNING): ipc_server.on_ready_read() msg = "In on_ready_read with None socket and old_socket!" - assert msg in [r.message for r in caplog.records] + assert msg in caplog.messages @pytest.mark.posix @@ -588,7 +582,7 @@ def test_ipcserver_socket_none_error(ipc_server, caplog): assert ipc_server._socket is None ipc_server.on_error(0) msg = "In on_error with None socket!" - assert msg in [r.message for r in caplog.records] + assert msg in caplog.messages class TestSendOrListen: @@ -627,8 +621,7 @@ class TestSendOrListen: def test_normal_connection(self, caplog, qtbot, args): ret_server = ipc.send_or_listen(args) assert isinstance(ret_server, ipc.IPCServer) - msgs = [e.message for e in caplog.records] - assert "Starting IPC server..." in msgs + assert "Starting IPC server..." in caplog.messages assert ret_server is ipc.server with qtbot.waitSignal(ret_server.got_args): @@ -667,8 +660,7 @@ class TestSendOrListen: ret = ipc.send_or_listen(args) assert ret is None - msgs = [e.message for e in caplog.records] - assert "Got AddressInUseError, trying again." in msgs + assert "Got AddressInUseError, trying again." in caplog.messages @pytest.mark.parametrize('has_error, exc_name, exc_msg', [ (True, 'SocketError', @@ -717,7 +709,7 @@ class TestSendOrListen: 'post_text: Maybe another instance is running but frozen?', 'exception text: {}'.format(exc_msg), ] - assert caplog.records[0].msg == '\n'.join(error_msgs) + assert caplog.messages[0] == '\n'.join(error_msgs) @pytest.mark.posix(reason="Flaky on Windows") def test_error_while_listening(self, qlocalserver_mock, caplog, args): @@ -739,7 +731,7 @@ class TestSendOrListen: ('exception text: Error while listening to IPC server: Error ' 'string (error 4)'), ] - assert caplog.records[-1].msg == '\n'.join(error_msgs) + assert caplog.messages[-1] == '\n'.join(error_msgs) @pytest.mark.windows diff --git a/tests/unit/misc/test_sessions.py b/tests/unit/misc/test_sessions.py index b9fcaf571..6c6ea669b 100644 --- a/tests/unit/misc/test_sessions.py +++ b/tests/unit/misc/test_sessions.py @@ -217,7 +217,7 @@ class TestSave: assert len(caplog.records) == 1 msg = "last_window_session is None while saving!" - assert caplog.records[0].msg == msg + assert caplog.messages[0] == msg assert not session_path.exists() def test_last_window_session(self, sess_man, tmpdir): diff --git a/tests/unit/misc/test_sql.py b/tests/unit/misc/test_sql.py index 54c785286..dff6144cc 100644 --- a/tests/unit/misc/test_sql.py +++ b/tests/unit/misc/test_sql.py @@ -68,14 +68,13 @@ class TestSqlError: with pytest.raises(sql.SqlBugError): sql.raise_sqlite_error("Message", sql_err) - lines = [r.message for r in caplog.records] expected = ['SQL error:', 'type: UnknownError', 'database text: db text', 'driver text: driver text', 'error code: 23'] - assert lines == expected + assert caplog.messages == expected @pytest.mark.parametrize('klass', [sql.SqlEnvironmentError, sql.SqlBugError]) diff --git a/tests/unit/test_app.py b/tests/unit/test_app.py index 1c2341d2b..a4f78a5ab 100644 --- a/tests/unit/test_app.py +++ b/tests/unit/test_app.py @@ -36,6 +36,5 @@ def test_on_focus_changed_issue1484(monkeypatch, qapp, caplog): app.on_focus_changed(buf, buf) assert len(caplog.records) == 1 - record = caplog.records[0] expected = "on_focus_changed called with non-QWidget {!r}".format(buf) - assert record.message == expected + assert caplog.messages[0] == expected diff --git a/tests/unit/utils/test_debug.py b/tests/unit/utils/test_debug.py index 518bf9b4a..2a78c5cba 100644 --- a/tests/unit/utils/test_debug.py +++ b/tests/unit/utils/test_debug.py @@ -42,7 +42,7 @@ def test_log_events(qapp, caplog): qapp.sendEvent(obj, QEvent(QEvent.User)) qapp.processEvents() assert len(caplog.records) == 1 - assert caplog.records[0].msg == 'Event in test_debug.EventObject: User' + assert caplog.messages[0] == 'Event in test_debug.EventObject: User' class SignalObject(QObject): @@ -75,8 +75,8 @@ def test_log_signals(caplog, signal_obj): signal_obj.signal2.emit('foo', 'bar') assert len(caplog.records) == 2 - assert caplog.records[0].msg == 'Signal in : signal1()' - assert caplog.records[1].msg == "Signal in : signal2('foo', 'bar')" + assert caplog.messages[0] == 'Signal in : signal1()' + assert caplog.messages[1] == "Signal in : signal2('foo', 'bar')" class TestLogTime: @@ -91,7 +91,7 @@ class TestLogTime: assert len(caplog.records) == 1 pattern = re.compile(r'Foobar took ([\d.]*) seconds\.') - match = pattern.fullmatch(caplog.records[0].msg) + match = pattern.fullmatch(caplog.messages[0]) assert match duration = float(match.group(1)) @@ -119,7 +119,7 @@ class TestLogTime: func(1, kwarg=2) assert len(caplog.records) == 1 - assert caplog.records[0].msg.startswith('Foo took') + assert caplog.messages[0].startswith('Foo took') class TestQEnumKey: diff --git a/tests/unit/utils/test_error.py b/tests/unit/utils/test_error.py index 951aa21f6..6b0679d35 100644 --- a/tests/unit/utils/test_error.py +++ b/tests/unit/utils/test_error.py @@ -61,7 +61,7 @@ def test_no_err_windows(caplog, exc, name, exc_text, fake_args): 'post_text: post', 'exception text: {}'.format(exc_text), ] - assert caplog.records[0].msg == '\n'.join(expected) + assert caplog.messages[0] == '\n'.join(expected) # This happens on Xvfb for some reason diff --git a/tests/unit/utils/test_jinja.py b/tests/unit/utils/test_jinja.py index b1a50772e..34b821dcd 100644 --- a/tests/unit/utils/test_jinja.py +++ b/tests/unit/utils/test_jinja.py @@ -109,8 +109,8 @@ def test_not_found(caplog): data = jinja.render('does_not_exist.html') assert "The does_not_exist.html template could not be found!" in data - assert caplog.records[0].msg.startswith("The does_not_exist.html template" - " could not be loaded from") + assert caplog.messages[0].startswith("The does_not_exist.html template" + " could not be loaded from") def test_utf8(): diff --git a/tests/unit/utils/test_log.py b/tests/unit/utils/test_log.py index 04e14a708..cefeda62e 100644 --- a/tests/unit/utils/test_log.py +++ b/tests/unit/utils/test_log.py @@ -271,7 +271,7 @@ def test_stub(caplog, suffix, expected): with caplog.at_level(logging.WARNING, 'misc'): log.stub(suffix) assert len(caplog.records) == 1 - assert caplog.records[0].message == expected + assert caplog.messages[0] == expected def test_ignore_py_warnings(caplog): @@ -281,7 +281,7 @@ def test_ignore_py_warnings(caplog): with caplog.at_level(logging.WARNING): warnings.warn("not hidden", UserWarning) assert len(caplog.records) == 1 - msg = caplog.records[0].message.splitlines()[0] + msg = caplog.messages[0].splitlines()[0] assert msg.endswith("UserWarning: not hidden") @@ -301,4 +301,4 @@ class TestQtMessageHandler: """Make sure there's no crash with an empty message.""" log.qt_message_handler(QtCore.QtDebugMsg, self.Context(), "") assert len(caplog.records) == 1 - assert caplog.records[0].msg == "Logged empty message!" + assert caplog.messages[0] == "Logged empty message!" diff --git a/tests/unit/utils/test_standarddir.py b/tests/unit/utils/test_standarddir.py index d337b39de..8edcf41b8 100644 --- a/tests/unit/utils/test_standarddir.py +++ b/tests/unit/utils/test_standarddir.py @@ -289,7 +289,7 @@ class TestInitCacheDirTag: with caplog.at_level(logging.ERROR, 'init'): standarddir._init_cachedir_tag() assert len(caplog.records) == 1 - assert caplog.records[0].message == 'Failed to create CACHEDIR.TAG' + assert caplog.messages[0] == 'Failed to create CACHEDIR.TAG' assert not tmpdir.listdir() @@ -455,8 +455,8 @@ class TestMove: def test_no_old_dir(self, dirs, caplog): """Nothing should happen without any old directory.""" standarddir._move_data(str(dirs.old), str(dirs.new)) - assert not any(rec.message.startswith('Migrating data from') - for rec in caplog.records) + assert not any(message.startswith('Migrating data from') + for message in caplog.messages) @pytest.mark.parametrize('empty_dest', [True, False]) def test_moving_data(self, dirs, empty_dest): @@ -475,10 +475,9 @@ class TestMove: with caplog.at_level(logging.ERROR): standarddir._move_data(str(dirs.old), str(dirs.new)) - record = caplog.records[-1] expected = "Failed to move data from {} as {} is non-empty!".format( dirs.old, dirs.new) - assert record.message == expected + assert caplog.messages[-1] == expected def test_deleting_error(self, dirs, monkeypatch, mocker, caplog): """When there was an error it should be logged.""" @@ -489,10 +488,9 @@ class TestMove: with caplog.at_level(logging.ERROR): standarddir._move_data(str(dirs.old), str(dirs.new)) - record = caplog.records[-1] expected = "Failed to move data from {} to {}: error".format( dirs.old, dirs.new) - assert record.message == expected + assert caplog.messages[-1] == expected @pytest.mark.parametrize('args_kind', ['basedir', 'normal', 'none']) diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index 9df7ed0d0..e77d33783 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -263,7 +263,7 @@ class TestFuzzyUrl: msg = ("URL contains characters which are not present in the current " "locale") - assert caplog.records[-1].message == msg + assert caplog.messages[-1] == msg @pytest.mark.parametrize('url, special', [ diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 2b38aadc4..5359dc675 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -471,8 +471,7 @@ class TestPreventExceptions: assert ret == 42 assert len(caplog.records) == 1 expected = 'Error in test_utils.TestPreventExceptions.func_raising' - actual = caplog.records[0].message - assert actual == expected + assert caplog.messages[0] == expected @utils.prevent_exceptions(42) def func_not_raising(self): @@ -691,7 +690,7 @@ class TestGetSetClipboard: utils.set_clipboard(text, selection=selection) assert not clipboard_mock.setText.called expected = 'Setting fake {}: "{}"'.format(what, expected) - assert caplog.records[0].message == expected + assert caplog.messages[0] == expected def test_get(self): assert utils.get_clipboard() == 'mocked clipboard text' @@ -742,7 +741,7 @@ class TestOpenFile: executable = shlex.quote(sys.executable) cmdline = '{} -c pass'.format(executable) utils.open_file('/foo/bar', cmdline) - result = caplog.records[0].message + result = caplog.messages[0] assert re.fullmatch( r'Opening /foo/bar with \[.*python.*/foo/bar.*\]', result) @@ -751,7 +750,7 @@ class TestOpenFile: executable = shlex.quote(sys.executable) cmdline = '{} -c pass {{}} raboof'.format(executable) utils.open_file('/foo/bar', cmdline) - result = caplog.records[0].message + result = caplog.messages[0] assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*'raboof'\]", result) @@ -761,7 +760,7 @@ class TestOpenFile: cmdline = '{} -c pass'.format(executable) config_stub.val.downloads.open_dispatcher = cmdline utils.open_file('/foo/bar') - result = caplog.records[1].message + result = caplog.messages[1] assert re.fullmatch( r"Opening /foo/bar with \[.*python.*/foo/bar.*\]", result) @@ -769,7 +768,7 @@ class TestOpenFile: m = mocker.patch('PyQt5.QtGui.QDesktopServices.openUrl', spec={}, new_callable=mocker.Mock) utils.open_file('/foo/bar') - result = caplog.records[0].message + result = caplog.messages[0] assert re.fullmatch( r"Opening /foo/bar with the system application", result) m.assert_called_with(QUrl('file:///foo/bar')) diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index 2120a4b97..60d8c4590 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -295,7 +295,7 @@ class TestGitStr: with caplog.at_level(logging.ERROR, 'misc'): assert version._git_str() == '0deadcode' assert len(caplog.records) == 1 - assert caplog.records[0].message == "Error while getting git path" + assert caplog.messages[0] == "Error while getting git path" def _has_git(): @@ -457,7 +457,7 @@ def test_release_info(files, expected, caplog, monkeypatch): assert version._release_info() == expected if files is None: assert len(caplog.records) == 1 - assert caplog.records[0].message == "Error while reading fake-file." + assert caplog.messages[0] == "Error while reading fake-file." @pytest.mark.parametrize('equal', [True, False])