FastAPI async tests skipped: pytest-asyncio "asyncio_mode" not set in CI
pytest-asyncio only runs async def tests when a mode is configured. If asyncio_mode is unset, async tests are collected but not awaited, so they emit a "coroutine was never awaited" warning and silently pass without executing assertions.
What this error means
CI is green but async FastAPI tests never actually run: you see "PytestUnhandledCoroutineWarning" or "coroutine ... was never awaited", and asserting a failure does not fail the build.
PytestUnraisableExceptionWarning: ...
RuntimeWarning: coroutine 'test_create_item' was never awaited
warnings.warn(...)Common causes
asyncio_mode is not configured
With the default strict mode and no per-test markers, or no mode at all, pytest-asyncio does not run the coroutine tests.
Missing per-test asyncio markers in strict mode
In strict mode each async test needs @pytest.mark.asyncio; unmarked ones are not awaited.
How to fix it
Set asyncio_mode in config
Configure the mode so async tests are awaited without a marker on every test.
[tool.pytest.ini_options]
asyncio_mode = "auto"Or mark each async test in strict mode
If you keep strict mode, mark every coroutine test so it runs.
import pytest
@pytest.mark.asyncio
async def test_create_item():
...How to prevent it
- Set
asyncio_modein pyproject or pytest.ini so async tests always run. - Fail the build on "coroutine was never awaited" warnings with a filter.
- Assert a known failure once to confirm async tests actually execute.