Skip to content

Releases: krylosov-aa/async-pytest-httpserver

2.1.0

Choose a tag to compare

@krylosov-aa krylosov-aa released this 16 Jun 06:34

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

Choose a tag to compare

@krylosov-aa krylosov-aa released this 16 Jun 03:39

Lowering dependency requirements for aiohttp and pytest

2.0.0

Choose a tag to compare

@krylosov-aa krylosov-aa released this 01 Jun 20:35

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.

1.0.1

Choose a tag to compare

@krylosov-aa krylosov-aa released this 08 Dec 21:44

simplified the examples

1.0.0

Choose a tag to compare

@krylosov-aa krylosov-aa released this 08 Dec 21:39

updated docs for release 1.0.0

0.1.1

Choose a tag to compare

@krylosov-aa krylosov-aa released this 07 Dec 21:20

licenses fix

0.1.0

Choose a tag to compare

@krylosov-aa krylosov-aa released this 07 Dec 15:29

initial release