本文へ移動

Python、Webアプリや製品・サービス開発についてhirokikyが書きます。

pytest-asyncioとpytest-aiohttpを一緒に使うとRuntimeError got Future attached to a different loopがでる

hirokikyはてなブックマーク

pytest-asyncio と pytest-aiohttp を同時に使うと、テストの中で使うイベントループが別のものになってしまってエラーが出ます。

RuntimeError: Task <Task pending coro=<...> cb=[...]> got Future <Future pending> attached to a different loop

pytest-dev/pytest-asynciogithub.com

aio-libs/pytest-aiohttpgithub.com

aiohttpを使ってるWebアプリのテストを書くときは pytest-aiohttp に寄せたほうが良さそうです。 pytest-aiohttp を使えば loop のフィクスチャーで、テストで使うイベントループが取れるのでそれに寄せるようにします。

Conflicts with pytest-asyncio (sample with redis) · Issue #8 · aio-libs/pytest-aiohttpgithub.com