Repository navigation
Releases: krylosov-aa/async-pytest-httpserver
Release list
2.1.0
Conflict policy
When two handlers are registered for overlapping routes, ConflictPolicy controls which one wins or whether registration raises an error.
Pass conflict_policy to the http_server factory:
from async_pytest_httpserver import ConflictPolicy
mock = await http_server(conflict_policy=ConflictPolicy.LAST_WINS)LAST_WINS (default)
The most recently registered handler takes priority. Earlier handlers remain in the pool as fallbacks for non-overlapping requests.
mock = await http_server()
mock.expect_request("/api", method="GET").respond_with_json({"v": 1})
mock.expect_request("/api", method="GET").respond_with_json({"v": 2})
resp = await client.get(mock.url_for("/api"))
data = await resp.json()
assert data == {"v": 2}FIRST_WINS
The first registered handler keeps priority. Later registrations for the same route are checked after the first one.
mock = await http_server(conflict_policy=ConflictPolicy.FIRST_WINS)
mock.expect_request("/api", method="GET").respond_with_json({"v": 1})
mock.expect_request("/api", method="GET").respond_with_json({"v": 2})
resp = await client.get(mock.url_for("/api"))
data = await resp.json()
assert data == {"v": 1}ERROR
Raises ConflictError at registration time if the new handler overlaps with an already-registered one in the same pool. Useful for catching accidental duplicate registrations.
from async_pytest_httpserver import ConflictPolicy, ConflictError
mock = await http_server(conflict_policy=ConflictPolicy.ERROR)
mock.expect_request("/api", method="GET").respond_with_json({"v": 1})
# Raises ConflictError — same path and method already registered
mock.expect_request("/api", method="GET").respond_with_json({"v": 2})Overlap detection is field-by-field: two matchers are considered non-overlapping when at least one dimension is provably incompatible (different exact paths, disjoint methods, different concrete query or header values, different JSON bodies). Conservative matchers (StartsWith, Contains, regex, json_contains=, composites) are treated as potentially overlapping.
Cross-pool registrations — e.g. an oneshot handler alongside a permanent one for the same route — are allowed regardless of policy.
2.0.1
Lowering dependency requirements for aiohttp and pytest
2.0.0
I finally decided to push this library to a production-ready state. Overall, I was inspired by the functionality of the synchronous pytest-httpserver, with some bits borrowed from respx.
These are major changes that completely break compatibility with version 1.0.1. So essentially, it's like a different library compared to the previous one.