I am trying to test an async function. Thus, I have an async test. When I use pycharm to set breakpoints in this test, they don't break. The things which are supposed to print to console do not print. And, the test takes 0 seconds. pytest lists the test as PASSED, but it clearly isn't actually executing the code in context.
Here is the code:
import unittest.mock
import pytest
from app.listener import ListenerCog
class ListenerCogTestCase(unittest.TestCase):
def setUp(self):
# Create a mock discord.Client object
self.client = unittest.mock.Mock()
# Create a ListenerCog instance and pass the mock client as the bot attribute
self.listener_cog = ListenerCog(self.client)
@pytest.mark.asyncio
async def test_on_ready(self):
# Call the on_ready method of the ListenerCog instance
await self.listener_cog.on_ready()
# Assert that the "Running!" message is printed
self.assertIn("Running!", self.stdout.getvalue())
What I've tried:
- enable
python.debug.asyncio.replin pycharm registry - add arguments to pytest including
--capture=no -sand--no-conv
Nothing seems to be working. Would really appreciate some guidance here if anyone is accustomed to debugging async tests.