Skip to content
Latchkey

Python "DeprecationWarning: There is no current event loop" in CI

In Python 3.10+, asyncio.get_event_loop() with no running loop is deprecated. When CI turns warnings into errors (-W error or filterwarnings), this DeprecationWarning fails the test that triggers it.

What this error means

A test fails with "DeprecationWarning: There is no current event loop" promoted to an error, usually from code or a library calling get_event_loop() outside a running loop.

pytest
DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()

Common causes

get_event_loop() called with no running loop

The deprecated implicit-loop behavior triggers the warning; with strict warnings it becomes a test failure.

An older library uses the deprecated pattern

A dependency still calls get_event_loop() the old way, and your strict warning filter surfaces it.

How to fix it

Use the modern loop APIs

  1. Replace asyncio.get_event_loop() with asyncio.new_event_loop()/asyncio.run() as appropriate.
  2. Inside a running context, use asyncio.get_running_loop().
  3. Re-run.
Python
import asyncio
# top-level entry
asyncio.run(main())
# inside async code that needs the loop
loop = asyncio.get_running_loop()

Scope the warning filter for a lagging dependency

When the warning is from a dependency you cannot fix yet, ignore just that warning instead of failing the suite.

pytest.ini
[pytest]
filterwarnings =
    error
    ignore:There is no current event loop:DeprecationWarning

How to prevent it

  • Use asyncio.run() / get_running_loop() instead of get_event_loop().
  • Upgrade libraries that still use the deprecated implicit loop.
  • Scope strict warning filters narrowly so only your own warnings fail.

Related guides

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