aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-17 19:13:18 -0700
committerGravatar MarkKoz <[email protected]>2020-08-17 19:13:18 -0700
commit282596d1414613e05ee8b956393913da976b35e3 (patch)
treee149f59a29b1817e9f3be3e5dffd88425847884d
parentSilence tests: create channel and overwrite in setUp for silence tests (diff)
Silence tests: fix mock for _init_task
An `AsyncMock` fails because it returns a coroutine which may only be awaited once. However, an `asyncio.Future` is perfect because it is easy to create and can be awaited repeatedly, just like the actual `asyncio.Task` that is being mocked.
-rw-r--r--tests/bot/cogs/moderation/test_silence.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/bot/cogs/moderation/test_silence.py b/tests/bot/cogs/moderation/test_silence.py
index eba8385bc..5d42d8c36 100644
--- a/tests/bot/cogs/moderation/test_silence.py
+++ b/tests/bot/cogs/moderation/test_silence.py
@@ -138,7 +138,8 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
def setUp(self) -> None:
self.bot = MockBot()
self.cog = Silence(self.bot)
- self.cog._init_task = mock.AsyncMock()()
+ self.cog._init_task = asyncio.Future()
+ self.cog._init_task.set_result(None)
asyncio.run(self.cog._init_cog()) # Populate instance attributes.
@@ -229,7 +230,8 @@ class UnsilenceTests(unittest.IsolatedAsyncioTestCase):
def setUp(self) -> None:
self.bot = MockBot()
self.cog = Silence(self.bot)
- self.cog._init_task = mock.AsyncMock()()
+ self.cog._init_task = asyncio.Future()
+ self.cog._init_task.set_result(None)
perms_cache = mock.create_autospec(self.cog.muted_channel_perms, spec_set=True)
self.cog.muted_channel_perms = perms_cache