Registry / testing / aresponses

aresponses

JSON →
library3.0.0pypypi✓ verified 84d ago

Asyncio response mocking library for aiohttp-based code, similar to responses for requests. Version 3.0.0 supports asyncio and aiohttp. Released sporadically.

pip install aresponses
INSTALL
IMPORT
SIG · ARESPONSES
A
aresponses
testingpythonv3.0.0
Install
5.1s avg
Import
1061ms
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.124s · 39.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.1s · import 0.998s · 42MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ResponsesMockServer
from aresponses import ResponsesMockServer
Class name with capital 'M' and capital 'S'

Basic usage of ResponsesMockServer context manager with aiohttp.

import aiohttp import asyncio from aresponses import ResponsesMockServer async def test_fetch(): async with aiohttp.ClientSession() as session: async with session.get('http://example.com/api') as resp: data = await resp.json() assert data == {'key': 'value'} async def main(): async with ResponsesMockServer() as server: server.add('http://example.com/api', 'GET', response={'key': 'value'}) await test_fetch() asyncio.run(main())
Debug
Known issues
gotchaResponsesMockServer must be used as an async context manager, not a regular context manager. Forgetting 'async with' will cause a RuntimeError.
fix
Use 'async with ResponsesMockServer() as server:'
affects: all
breakingVersion 3.0.0 changed the API from the old 'aresponses' function-based approach to the class-based 'ResponsesMockServer'. Old code using 'aresponses.match' or 'aresponses.add' directly no longer works.
fix
Replace 'aresponses.match(...)' with 'ResponsesMockServer().add(...)' and use async context manager.
affects: >=3.0.0
deprecatedThe 'aresponses' module-level functions like 'aresponses.add' and 'aresponses.match' are removed in 3.0.0. Direct attribute access to 'RequestsMock' is no longer supported.
fix
Import 'ResponsesMockServer' and use its async context manager.
affects: >=3.0.0
gotcharesponses (the synchronous library) is sometimes confused with aresponses. Ensure you import from 'aresponses' not 'responses'.
fix
Use 'from aresponses import ...'
affects: all
Errors
Common errors & fixes
AttributeError: module 'aresponses' has no attribute 'match'
Trying to use old API pattern (aresponses.match) in version 3.0.0.
fix
Use 'ResponsesMockServer' class with 'add' method instead: 'from aresponses import ResponsesMockServer' and use 'server.add(...)'.
RuntimeError: cannot use async context manager outside of an async function
Using 'with ResponsesMockServer()' instead of 'async with' inside an async function.
fix
Change 'with' to 'async with' inside an async function.
Upgrade
Version history
3.0.0latest on PyPI · released Jan 12, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
aresponses — pip install aresponses · libregistry