diff options
author | 2022-10-10 21:53:00 +0100 | |
---|---|---|
committer | 2022-10-10 21:55:30 +0100 | |
commit | a1f4f60147ce3fd0e909baa37795d5db8f68bf30 (patch) | |
tree | fa7bef5d48cf1d3654d1c88afffee4d4f880ba62 /tests | |
parent | noqa an abstract class with no abstract methods (diff) |
Use explicit mock channels in tests to remove warning
This is need due to the new behaviour of discord.utils.get supporting both iterables and async iterables by checking for the presence of the __aiter__ attr on the iterable.
GuildChannelConverter._resolve_channel uses this get util under the hood which grabs the voice channels on the guild, which were previously Mocked by the MagicMock, meaning the __aiter__ attr was present, causing the util to think it should be ran asynchronously.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/exts/backend/test_error_handler.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/tests/bot/exts/backend/test_error_handler.py b/tests/bot/exts/backend/test_error_handler.py index 7562f6aa8..eae1bae20 100644 --- a/tests/bot/exts/backend/test_error_handler.py +++ b/tests/bot/exts/backend/test_error_handler.py @@ -9,7 +9,7 @@ from bot.exts.backend import error_handler from bot.exts.info.tags import Tags from bot.exts.moderation.silence import Silence from bot.utils.checks import InWhitelistCheckFailure -from tests.helpers import MockBot, MockContext, MockGuild, MockRole, MockTextChannel +from tests.helpers import MockBot, MockContext, MockGuild, MockRole, MockTextChannel, MockVoiceChannel class ErrorHandlerTests(unittest.IsolatedAsyncioTestCase): @@ -192,7 +192,16 @@ class TrySilenceTests(unittest.IsolatedAsyncioTestCase): self.bot = MockBot() self.silence = Silence(self.bot) self.bot.get_command.return_value = self.silence.silence - self.ctx = MockContext(bot=self.bot) + + # Use explicit mock channels so that discord.utils.get doesn't think + # guild.text_channels is an async iterable due to the MagicMock having + # a __aiter__ attr. + guild_overrides = { + "text_channels": [MockTextChannel(), MockTextChannel()], + "voice_channels": [MockVoiceChannel(), MockVoiceChannel()], + } + self.guild = MockGuild(**guild_overrides) + self.ctx = MockContext(bot=self.bot, guild=self.guild) self.cog = error_handler.ErrorHandler(self.bot) async def test_try_silence_context_invoked_from_error_handler(self): |