Skip to content
Latchkey

Python "RuntimeWarning: coroutine was never awaited" in CI

You called an async def function but never awaited the coroutine it returned, so its body never ran. Python emits a RuntimeWarning - which becomes a hard failure under warnings-as-errors and a silent bug otherwise.

What this error means

A run logs RuntimeWarning: coroutine 'X' was never awaited, and the awaited work appears to do nothing. Under -W error or pytest filterwarnings = error, the warning turns into an error and fails the test or job.

Python output
sys:1: RuntimeWarning: coroutine 'fetch_data' was never awaited
# under warnings-as-errors:
RuntimeWarning: coroutine 'fetch_data' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Common causes

Async function called without await

Calling fetch_data() returns a coroutine object; without await (or scheduling it on the loop) the body never executes and Python warns at GC time.

Async test not marked/awaited

A test defined async def but not collected as async (missing pytest-asyncio marker/mode) is called as a coroutine and never awaited, so its assertions never run.

How to fix it

Await the coroutine (or schedule it)

Await directly in async code, or use asyncio.run at the top level.

Python
# inside an async function
result = await fetch_data()
# at the top level
result = asyncio.run(fetch_data())

Mark async tests so they are awaited

Enable pytest-asyncio so async def tests actually run.

pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"   # collects and awaits async tests

How to prevent it

  • Always await coroutines or run them with asyncio.run.
  • Enable pytest-asyncio so async tests are collected and awaited.
  • Run with warnings-as-errors in CI to catch un-awaited coroutines.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →