Pytest Tips¶
公式ドキュメント¶
Fixture¶
非同期のfixture¶
pytest_asyncio
をインポートして、@pytest.mark.asyncio
を使うことで非同期のfixtureを定義できる。
import pytest
import pytest_asyncio
from collections.abc import AsyncGenerator
@pytest_asyncio.fixture()
async def fixture() -> AsyncGenerator[str, None]:
yield "a"
@pytest.mark.asyncio
async def test(fixture: str):
assert fixture == "a"