bot icon indicating copy to clipboard operation
bot copied to clipboard

Fix not awaited coroutine warning

Open wookie184 opened this issue 3 years ago • 0 comments

Fixes this warning in the tests:

tests/bot/exts/moderation/infraction/test_infractions.py::VoiceMuteTests::test_voice_mute_truncate_reason
  c:\users\wookie\appdata\local\programs\python\python39\lib\enum.py:384: RuntimeWarning: coroutine 'Infractions.apply_voice_mute.<locals>.action' was never awaited
  Coroutine created at (most recent call last)
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\unittest\async_case.py", line 87, in _callMaybeAsync
      return self._asyncioTestLoop.run_until_complete(fut)
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 634, in run_until_complete
      self.run_forever()
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 601, in run_forever
      self._run_once()
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 1897, in _run_once
      handle._run()
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\asyncio\events.py", line 80, in _run
      self._context.run(self._callback, *self._args)
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\unittest\async_case.py", line 101, in _asyncioLoopRunner
      ret = await awaitable
    File "c:\users\wookie\appdata\local\programs\python\python39\lib\unittest\mock.py", line 1353, in patched
      return await func(*newargs, **newkeywargs)
    File "C:\Users\wookie\Documents\GitHub\bot\tests\bot\exts\moderation\infraction\test_infractions.py", line 139, in test_voice_mute_mod_log_ignore
      self.assertIsNone(await self.cog.apply_voice_mute(self.ctx, self.user, "foobar"))
    File "C:\Users\wookie\Documents\GitHub\bot\bot\decorators.py", line 218, in wrapper
      return await func(*args, **kwargs)
    File "C:\Users\wookie\Documents\GitHub\bot\bot\exts\moderation\infraction\infractions.py", line 496, in apply_voice_mute
      await self.apply_infraction(ctx, infraction, user, action())
    return cls.__new__(cls, value)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Passing coroutines around is not ideal, so I changed it so a coroutine function is passed instead. Some changes in the tests were also required.

wookie184 avatar Aug 04 '22 16:08 wookie184