pytest-async

raw JSON →
0.1.1 verified Mon Apr 27 auth: no python maintenance

pytest-async is a lightweight Pytest plugin for testing async functions. It automatically runs coroutines in an event loop without requiring decorators like @pytest.mark.asyncio. Current version 0.1.1 targets Python >=3.6. It is in maintenance mode with limited updates.

pip install pytest-async==0.1.1
error DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
cause pytest-async 0.1.1 uses deprecated collections imports not compatible with Python 3.9+.
fix
Upgrade to Python 3.8 or lower, or switch to pytest-asyncio.
error TypeError: object NoneType can't be used in 'await' expression
cause Test function is not properly awaited; possible mixing with synchronous test runner.
fix
Ensure test function is defined with 'async def' and that pytest-async is installed correctly. If using pytest-asyncio, add @pytest.mark.asyncio.
gotcha pytest-async automatically runs ALL coroutines in tests, including fixtures. Avoid defining async fixtures that are not meant to be tests, as they may be executed inadvertently.
fix Use synchronous fixtures or mark non-test async functions with @pytest.fixture but note that pytest-async may still attempt to run them. Consider using pytest-asyncio for more control.
deprecated pytest-async is no longer actively maintained. The recommended alternative is pytest-asyncio, which is actively developed and supports Python 3.7+.
fix Migrate to pytest-asyncio: install pytest-asyncio, remove pytest-async, and add @pytest.mark.asyncio decorator to async tests.

Define async test functions directly; no decorator needed. Pytest automatically runs them in an event loop.

# test_async.py
async def test_async_func():
    assert await some_async_call()

async def some_async_call():
    return 42