Configures and runs async Python tests with pytest-asyncio: installs the plugin, selects asyncio_mode (auto vs strict), scopes event loops (function/class/module/session), writes async fixtures with @pytest_asyncio.fixture, mocks coroutines with AsyncMock, and tests FastAPI (httpx.AsyncClient + ASGITransport) and aiohttp (aiohttp_client fixture) applications. Use when a Python project contains async def test_ functions, FastAPI/aiohttp endpoints, or any asyncio-based code that needs pytest integration. Do NOT use for general pytest fixture design, parametrize patterns, or conftest.py structure without an asyncio-specific problem (event-loop scoping, mode config, AsyncMock, ASGI client): use pytest-tests for those.
79
99%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Await-specific assertions and side_effect semantics for
unittest.mock.AsyncMock (stdlib since Python 3.8). The SKILL.md spine keeps
the primary AsyncMock example; the exhaustive assertion reference is here.
Source: docs.python.org AsyncMock.
@pytest.mark.asyncio
async def test_external_call():
with patch("myapp.clients.redis.get", new_callable=AsyncMock) as mock_get:
mock_get.return_value = b"cached"
result = await fetch_from_cache("key")
mock_get.assert_awaited_once_with("key")
assert result == b"cached"new_callable=AsyncMock is required so patch installs a coroutine-returning
mock rather than a plain MagicMock.
| Assertion | Meaning |
|---|---|
assert_awaited_once_with(*a, **kw) | Awaited exactly once with these args |
assert_awaited_with(*a, **kw) | Last await had these args |
assert_any_await(*a, **kw) | Ever awaited with these args |
assert_not_awaited() | Never awaited |
await_count | How many times awaited (attribute, not assertion) |
The assert_called_* family checks that the mock was called, not that it
was awaited; a coroutine mock can be called without being awaited, so prefer
the assert_awaited_* family for async code.
side_effect on AsyncMock behaves the same as on a sync mock: a callable is
invoked and its result returned; an exception class (or instance) is raised
when the mock is awaited; an iterable returns successive values on each await.