pytest: async def functions are not natively supported (tested)
Failed: async def functions are not natively supported means pytest found an async def test but no plugin to run it. Install pytest-asyncio and mark the test with @pytest.mark.asyncio, or set asyncio_mode = auto; in its default strict mode the plugin ignores unmarked tests.
1. Reproduce it: an async test without a plugin
import asyncio
async def test_sleep():
await asyncio.sleep(0)
assert True
$ pytest -q test_async.py
F [100%]
=================================== FAILURES ===================================
__________________________________ test_sleep __________________________________
async def functions are not natively supported.
You need to install a suitable plugin for your async framework, for example:
- anyio
- pytest-asyncio
- pytest-tornasync
- pytest-trio
- pytest-twisted
=========================== short test summary info ============================
FAILED test_async.py::test_sleep - Failed: async def functions are not native...
1 failed in 0.02s
pytest itself cannot run coroutines. On pytest 9.1.1 an async def test with no async plugin fails with Failed: async def functions are not natively supported.
2. Installed pytest-asyncio, still failing: strict mode needs a marker
$ pip install pytest-asyncio # 1.4.0; test unchanged
$ pytest -q test_async.py
async def functions are not natively supported.
FAILED test_async.py::test_sleep - Failed: async def functions are not native...
1 failed in 0.00s
Installing pytest-asyncio alone did not change anything: its default mode is strict, which only runs async tests marked with @pytest.mark.asyncio. Also check that the plugin is installed in the same environment as the pytest you run (python -m pytest uses the active interpreter).
3. Fix: mark the test, or switch to auto mode
import asyncio
import pytest
@pytest.mark.asyncio
async def test_sleep():
await asyncio.sleep(0)
assert True
$ pytest -q m/test_async.py # with @pytest.mark.asyncio
1 passed in 0.00s
$ cat auto/pytest.ini
[pytest]
asyncio_mode = auto
$ cd auto && pytest -q test_async.py # no marker
1 passed in 0.00s
Either add @pytest.mark.asyncio to each async test (or pytestmark = pytest.mark.asyncio once at the top of a module), or set asyncio_mode = auto in pytest.ini (or [tool.pytest.ini_options] in pyproject.toml) so every async def test runs without a marker. Auto mode is simplest when asyncio is the only async framework in the project; with anyio or trio, use their own plugin instead.
Related: pytest error vs failure, pytest Failed: DID NOT RAISE.
Frequently asked questions
How do I fix async def functions are not natively supported?
pip install pytest-asyncio, then mark async tests with @pytest.mark.asyncio or set asyncio_mode = auto in pytest.ini or pyproject.toml.
Why does the error persist after installing pytest-asyncio?
pytest-asyncio's default strict mode only runs tests marked @pytest.mark.asyncio; unmarked async tests still fail. Also make sure it is installed in the environment pytest runs in.
Written with AI assistance. Measured on 2026-10-23 with pytest 9.1.1, pytest-asyncio 1.4.0 and Python 3.13.5 on Linux. Each command was run verbatim and the output pasted unedited (filtered where a grep or tail is shown). PlainHeaders is our extension; Python and pytest are free.