pook is an HTTP traffic mocking library for Python, enabling easy setup of expectations and interception of requests from popular HTTP clients like `requests`, `httpx`, and `aiohttp`. It supports various matching criteria for requests and provides flexible response definitions. The current version is 2.1.6, and it typically sees several patch releases per major version, though releases can sometimes be delayed.
pip install pookVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to mock an HTTP GET request using `pook` with the `requests` library. It sets up an expectation for a specific URL, activates the mock, makes the request, and then asserts the mocked response. Remember to deactivate and flush mocks to prevent state leakage between tests.
Remove the `binary` parameter from `pook.response().body()`. Ensure `chunked` is passed as a keyword argument (e.g., `body('content', chunked=True)`).Upgrade your Python environment to 3.10 or newer. For projects requiring older Python versions, pin `pook<2.1.0` (for Python 3.8) or `pook<2.1.5` (for Python 3.9/PyPy 3.10).
Upgrade to `pook` version 2.1.1 or newer. This version includes a fix to automatically flush mocks when `pook.activate` is used as a decorator or context manager. Always ensure `pook.flush()` is called after each test or test suite runs.
Carefully review your mock definition (`pook.get('url', ...)`) and the actual outgoing request to ensure all criteria (URL, method, headers, query, body) exactly match. Ensure `pook` is activated for the scope of the request.Remove the `binary=True/False` argument from your `pook.response().body()` call. `pook` now handles byte encoding automatically.
Ensure all mocks you define are actually hit by an outgoing HTTP request. If a mock is optional or should not trigger an error if uncalled, use `times(0)` or `persist()` as appropriate.
Install `pook` using pip: `pip install pook`. If using a virtual environment, ensure it is activated.
No dependency data recorded yet.