RuntimeWarning
PythonWARNINGNotableWarningHIGH confidence

Suspicious runtime behaviour

Production Risk

Forgotten awaits are a common async bug; treat RuntimeWarning as an error in tests.

What this means

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.

Why it happens
  1. 1An async function was called but the coroutine was never awaited
  2. 2A coroutine was created and immediately garbage collected without running
How to reproduce

Calling an async function without await.

trigger — this will error
trigger — this will error
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

Always await 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.

Code examples
Triggerpython
async def fetch(): return 1
result = fetch()  # RuntimeWarning: coroutine was never awaited
Handle in testspython
import warnings
warnings.simplefilter("error", RuntimeWarning)
# Unawaited coroutines will cause test failure
Avoid by awaiting all coroutinespython
import asyncio
async def main():
    result = await fetch()  # always await coroutines
asyncio.run(main())
What not to do

Suppress RuntimeWarning for unawaited coroutines

The coroutine never ran — its side effects and return value are lost, causing silent bugs.

Sources
Official documentation ↗

Python Docs — Built-in Exceptions

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Python errors