'Test with a mock and an exception in the block.'

def test_mock_commit_failed(self, qsavefile_mock):

    qsavefile_mock.open.return_value = True
    qsavefile_mock.commit.return_value = False
    with pytest.raises(OSError, match='Commit    failed!'):
        with qtutils.savefile_open('filename'):
            pass
    qsavefile_mock.open.assert_called_once_with(QIODevice.WriteOnly)
    assert (not qsavefile_mock.cancelWriting.called)
    assert (not qsavefile_mock.errorString.called)
