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.
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
- Replace
asyncio.get_event_loop()withasyncio.new_event_loop()/asyncio.run()as appropriate. - Inside a running context, use
asyncio.get_running_loop(). - Re-run.
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]
filterwarnings =
error
ignore:There is no current event loop:DeprecationWarningHow to prevent it
- Use
asyncio.run()/get_running_loop()instead ofget_event_loop(). - Upgrade libraries that still use the deprecated implicit loop.
- Scope strict warning filters narrowly so only your own warnings fail.