Sphere
Log in Join
☆ 5

Testing async code without pytest-asyncio event loop headaches

I keep fighting deprecation warnings about the event_loop fixture. Tests pass but the warnings pile up. What is the current recommended setup with pytest 8?

⚑ Report

3 replies

☆ 0
N Nina ·2026-10-02#1

Use pytest.mark.anyio with anyio backend asyncio and drop the event_loop fixture entirely. It avoids the deprecated API.

⚑ Report
☆ 0
D Dan H. ·2026-10-02#2

I have about 60 tests marked with pytest.mark.asyncio. Do I need to rewrite all of them?

⚑ Report
☆ 0
O Owen ·2026-10-02#3

You can set asyncio_mode=auto in pytest.ini and keep the old marks for now. The warnings come from custom event_loop fixtures, so delete those and let the plugin own the loop.

⚑ Report
Log in to reply.