How to test async function using pytest?

This works for me, please try:

import asyncio
import pytest

pytest_plugins = ('pytest_asyncio',)

@pytest.mark.asyncio
async def test_simple():
    await asyncio.sleep(0.5)

Output of pytest -v confirms it passes:

collected 1 item
test_async.py::test_simple PASSED

And I have installed:

pytest                        6.2.5
pytest-asyncio                0.16.0
# anyio not installed

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)