Suspicious runtime behaviour
Production Risk
Forgotten awaits are a common async bug; treat RuntimeWarning as an error in tests.
Issued for warnings about dubious runtime behaviour such as coroutines that were created but never awaited, or integer division that produces a float where an int was expected.
- 1An async function was called but the coroutine was never awaited
- 2A coroutine was created and immediately garbage collected without running
Calling an async function without await.
import asyncio
async def fetch():
await asyncio.sleep(1)
return "data"
# BUG: forgot await
result = fetch() # creates coroutine but never runs it
print(result)expected output
<coroutine object fetch at 0x...> RuntimeWarning: coroutine 'fetch' was never awaited
Fix
Always await async functions
WHEN Calling async functions
import asyncio
async def main():
result = await fetch() # Correctly awaited
print(result)
asyncio.run(main())Why this works
await evaluates the coroutine and returns its result; without it, you only get the coroutine object.
async def fetch(): return 1 result = fetch() # RuntimeWarning: coroutine was never awaited
import warnings
warnings.simplefilter("error", RuntimeWarning)
# Unawaited coroutines will cause test failureimport asyncio
async def main():
result = await fetch() # always await coroutines
asyncio.run(main())✕ Suppress RuntimeWarning for unawaited coroutines
The coroutine never ran — its side effects and return value are lost, causing silent bugs.
Python Docs — Built-in Exceptions
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev