Fix error handling when JSON can not be parsed.

This commit is contained in:
Fjerkroa Auto
2023-03-24 15:29:13 +01:00
parent 78591ef13a
commit 72c7d83766
2 changed files with 38 additions and 29 deletions
+2 -3
View File
@@ -1,6 +1,5 @@
import os
import unittest
import pytest
import aiohttp
import json
import toml
@@ -118,8 +117,8 @@ class TestFunctionality(TestBotBase):
message = self.create_message("Hello there! How are you?")
with patch.object(openai.ChatCompletion, 'acreate', new=acreate), \
patch.object(logging, 'warning', logging_warning):
with pytest.raises(RuntimeError, match='failed.*JSONDecodeError.*'):
await self.bot.on_message(message)
await self.bot.on_message(message)
self.bot.staff_channel.send.assert_called_once_with("ERROR: I could not parse this answer: '{ \"test\": 3 ]'", suppress_embeds=True)
async def test_on_message_event4(self) -> None:
async def acreate(*a, **kw):