Skip to content
This repository was archived by the owner on Oct 30, 2026. It is now read-only.

Use requests-mock for requests interception - #3576

Closed
adamtheturtle wants to merge 2 commits into
mainfrom
codex/use-requests-mock
Closed

adamtheturtle wants to merge 2 commits into
mainfrom
codex/use-requests-mock

Conversation

@adamtheturtle

@adamtheturtle adamtheturtle commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Summary

  • replace the in-process requests interceptor from responses to requests-mock
  • adapt the existing (status, headers, body) route callbacks to requests-mock response contexts
  • preserve binary response bodies, nested mocks, custom base URLs, real_http, and the existing unmatched-request ConnectionError behavior
  • use mock-response-delay's new requests-mock callback wrapper, which reads the public request.timeout attribute directly
  • move responses from runtime dependencies to the dev extra, where unrelated response-fixture tests still use it

This is the consumer migration for adamtheturtle/mock-response-delay#7. Until that change is released, the dependency is an exact direct reference to its green commit. Using a project dependency rather than a tool.uv.sources override is intentional: this repository's documentation and Docker workflows install the project with pip, which does not read uv source overrides. Replace the direct reference with the released version floor before making this PR ready to merge.

The underlying requests-mock timeout annotation is also being corrected upstream in jamielennox/requests-mock#276. This branch does not need a patched wheel to run: its callback boundary is structurally typed at runtime and uses requests-mock's public stub types during static checking.

Compatibility details

requests-mock has two relevant behavioral differences from responses:

  1. A callback registered as content must return bytes. The adapter therefore UTF-8 encodes string route bodies and leaves existing byte bodies untouched.
  2. An unmatched request normally raises requests_mock.exceptions.NoMockAddress. When real_http=False, this branch registers a lowest-priority catch-all which raises requests.exceptions.ConnectionError, preserving the behavior callers and tests already observe. Real HTTP passthrough remains controlled by Mocker(real_http=True).

Route registrations are added after the catch-all because requests-mock evaluates matchers in reverse registration order, so Vuforia routes retain precedence.

Validation

  • uv run --extra dev prek run --all-files --hook-stage pre-commit
  • uv run --extra dev prek run --all-files --hook-stage pre-push
  • all manual hooks: changed-file pylint, pylint-docs, documentation build, spelling, and linkcheck
  • tests/mock_vws/test_requests_mock_usage.py --skip-backend=real with example credentials: 107 passed, 2 skipped
  • pip dry-run of .[dev], resolving mock-response-delay from the exact Git commit
  • git diff --check

The all-files local pylint run also reports the pre-existing spelling finding for "subclasses" in tests/mock_vws/utils/retries.py; the same exact main SHA has a successful GitHub Lint workflow, and pylint passes for every file changed by this PR.

@adamtheturtle

Copy link
Copy Markdown
Member Author

Closing because we decided to keep the existing responses backend. No consumer migration is needed; the remaining typing mismatch will be addressed upstream in getsentry/responses.

This branch was previously deployed

2 inactive deployments
development — e316a548 Deployed Sep 8, 2026 by adamtheturtle via pages #1994
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant