Quick reference for common debugging scenarios in SummaryBot-NG
# ❌ WRONG
result = async_function()
# ✅ CORRECT
result = await async_function()from unittest.mock import AsyncMock, MagicMock
# ✅ Async methods
mock.async_method = AsyncMock()
await mock.async_method()
# ✅ Sync properties
mock.sync_property = MagicMock()
value = mock.sync_propertyimport inspect
result = method_that_might_be_async()
if inspect.iscoroutine(result):
result = await resultimport pytest_asyncio
@pytest_asyncio.fixture # Not @pytest.fixture
async def async_fixture():
resource = await create_resource()
yield resource
await resource.cleanup()import pytest
@pytest.fixture
def sync_fixture():
return create_config()from unittest.mock import MagicMock, AsyncMock
mock_interaction = MagicMock()
mock_interaction.user.id = 12345 # Sync property
mock_interaction.response = MagicMock()
mock_interaction.response.is_done.return_value = False # Sync
mock_interaction.response.send_message = AsyncMock() # Async# ❌ WRONG - Returns MagicMock
mock_result.embed_dict = MagicMock()
# ✅ CORRECT - Real values
mock_result.embed_dict = {
"title": "Summary",
"color": 0x00FF00, # int, not MagicMock
"fields": []
}# ✅ Handle exception
try:
self.client.tree = discord.app_commands.CommandTree(self.client)
except discord.errors.ClientException:
logger.debug("Using existing tree")# ❌ WRONG
assert "Rate Limit" in str(call_args)
# ✅ CORRECT
embed = call_args.kwargs['embed']
assert "Rate Limit" in embed.titlepoetry run pytest tests/path/test_file.py::TestClass::test_method -vpoetry run pytest tests/ -v --tb=shortpoetry run pytest tests/integration/ -vpoetry run pytest tests/ -x@pytest.mark.asyncio
@pytest.mark.parametrize("value,expected", [(1, "a"), (2, "b")])
async def test_param(value, expected):
result = await process(value)
assert result == expected@pytest.mark.asyncio
async def test_exception():
with pytest.raises(CustomError):
await function_that_raises()@pytest_asyncio.fixture
async def resource():
r = await create()
yield r
await r.cleanup() # Always runstests/
unit/ # Fast, isolated tests
integration/ # Tests with real components
e2e/ # Full system tests
fixtures/ # Shared test fixtures
conftest.py # Global fixtures
- Test marked with
@pytest.mark.asyncio? - Async fixture using
@pytest_asyncio.fixture? - All async calls awaited?
- Mocks configured correctly (AsyncMock vs MagicMock)?
- Real values in mock returns (not MagicMock)?
- Assertions on actual values (not strings)?
- Cleanup in fixture yield?
Add inspect.iscoroutine() check
Change @pytest.fixture to @pytest_asyncio.fixture
Add try-except around tree creation
Return real values instead of MagicMock
Assert on object attributes, not string repr
See Also:
DEBUG_FIXES_REPORT.md- Detailed bug analysisASYNC_TESTING_GUIDE.md- Comprehensive async testing guide