wiremock-mock¶
wiremock-mock serves WireMock stubs as a mock with respx.
Requires Python 3.12+.
Installation¶
pip install wiremock-mock
Usage¶
"""Example usage of wiremock-mock."""
from http import HTTPStatus
from typing import Any
import httpx
import respx
from wiremock_mock import add_wiremock_to_respx
stubs: dict[str, Any] = {
"mappings": [
{
"request": {"method": "GET", "urlPath": "/v1/pages"},
"response": {
"status": 200,
"jsonBody": {"object": "list", "results": []},
},
},
],
}
with respx.mock(
base_url="http://notion-mock.test", assert_all_called=False
) as m:
add_wiremock_to_respx(
mock_obj=m, stubs=stubs, base_url="http://notion-mock.test"
)
response = httpx.get(url="http://notion-mock.test/v1/pages")
assert response.status_code == HTTPStatus.OK
This lets you use existing WireMock stub files (e.g. from the WireMock Admin
API import format) without running WireMock in Docker. All HTTP traffic is
mocked at the httpx level via respx. To load stubs from a JSON file, use
json.loads(path.read_text()).
Use cases¶
Use existing WireMock stub files without running WireMock in Docker
Test against external APIs (e.g. Notion) without network access
Reuse stubs exported from WireMock Admin API or recorded mappings
Run tests in CI without Docker/socket dependencies
Supported stub features¶
Request matching:
method,urlPath(exact),urlPathPattern(regex)Query parameters:
queryParameterswithequalToResponse:
status,headers,jsonBody,body