Fix test_backup_error.

- Need caplog at level error
- Rename test to be unique
This commit is contained in:
Ryan Roden-Corrent 2018-03-13 08:50:34 -04:00
parent 27966c94a6
commit 73517f0a51

View File

@ -183,14 +183,15 @@ class TestFileHandling:
# content has not changed, so no backup should be created # content has not changed, so no backup should be created
assert not message_mock.messages assert not message_mock.messages
def test_backup(self, qtbot, message_mock, mocker): def test_backup_error(self, qtbot, message_mock, mocker, caplog):
editor = editormod.ExternalEditor(watch=True) editor = editormod.ExternalEditor(watch=True)
editor.edit('foo') editor.edit('foo')
with qtbot.wait_signal(editor.file_updated): with qtbot.wait_signal(editor.file_updated):
_update_file(editor._filename, 'bar') _update_file(editor._filename, 'bar')
mocker.patch('tempfile.NamedTemporaryFile', side_effect=OSError) mocker.patch('tempfile.NamedTemporaryFile', side_effect=OSError)
editor.backup() with caplog.at_level(logging.ERROR):
editor.backup()
msg = message_mock.getmsg(usertypes.MessageLevel.error) msg = message_mock.getmsg(usertypes.MessageLevel.error)
assert msg.text.startswith('Failed to create editor backup:') assert msg.text.startswith('Failed to create editor backup:')