Skip to content

Fix some test warnings#2675

Merged
ChrisLovering merged 2 commits into
mainfrom
fix-test-warnings
Jul 9, 2023
Merged

Fix some test warnings#2675
ChrisLovering merged 2 commits into
mainfrom
fix-test-warnings

Conversation

@wookie184
Copy link
Copy Markdown
Contributor

Currently these warnings are raised when running tests:

tests/bot/exts/backend/test_logging.py::LoggingTests::test_debug_mode_false
tests/bot/exts/backend/test_logging.py::LoggingTests::test_debug_mode_true
  C:\Users\wookie\Documents\GitHub\bot\bot\exts\backend\logging.py:18: RuntimeWarning: coroutine 'Logging.startup_greeting' was never awaited
    scheduling.create_task(self.startup_greeting(), event_loop=self.bot.loop)
  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.

tests/bot/exts/moderation/test_incidents.py: 27 warnings
  C:\Users\wookie\Documents\GitHub\bot\bot\exts\moderation\incidents.py:322: RuntimeWarning: coroutine 'Incidents.fetch_webhook' was never awaited
    scheduling.create_task(self.fetch_webhook(), event_loop=self.bot.loop)
  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.

tests/bot/exts/moderation/test_incidents.py: 27 warnings
  C:\Users\wookie\Documents\GitHub\bot\bot\exts\moderation\incidents.py:325: RuntimeWarning: coroutine 'Incidents.crawl_incidents' was never awaited
    self.crawl_task = scheduling.create_task(self.crawl_incidents(), event_loop=self.bot.loop)
  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.

tests/bot/exts/moderation/test_incidents.py::TestMakeConfirmationTask::test_make_confirmation_task_check
  C:\Users\wookie\Documents\GitHub\bot\tests\bot\exts\moderation\test_incidents.py:461: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    self.cog_instance.make_confirmation_task(MockMessage(id=123))
  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

This fixes that by patching create_task to just close the coroutine in these places.

I also removed some unnecessary bot.loop arguments to create_task.

wookie184 added 2 commits July 8, 2023 18:03
This is not necessary as the current event loop will be used which is the same as self.bot.loop. Removing these should slightly improve test speed as the mock for self.bot.loop doesn't need to be created.
Copy link
Copy Markdown
Contributor

@Xithrius Xithrius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfection

@Xithrius Xithrius enabled auto-merge (squash) July 9, 2023 05:31
@ChrisLovering ChrisLovering disabled auto-merge July 9, 2023 08:44
@ChrisLovering ChrisLovering merged commit a5b8099 into main Jul 9, 2023
@ChrisLovering ChrisLovering deleted the fix-test-warnings branch July 9, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants