Skip to content

Comments

Make MockVWS intercept both requests and httpx#2998

Merged
adamtheturtle merged 4 commits intomainfrom
adamtheturtle/switch-responses-httpx
Feb 22, 2026
Merged

Make MockVWS intercept both requests and httpx#2998
adamtheturtle merged 4 commits intomainfrom
adamtheturtle/switch-responses-httpx

Conversation

@adamtheturtle
Copy link
Member

@adamtheturtle adamtheturtle commented Feb 22, 2026

Summary

  • MockVWS now intercepts both requests (via responses) and httpx (via respx) simultaneously
  • Removed MockVWSForHttpx class entirely — a single MockVWS class handles both HTTP libraries
  • Simplified API: users no longer need to choose between two classes
  • Updated all tests, documentation, and examples to reflect this change

Test plan

  • ✅ All 49 existing tests pass (test suite covers both requests and httpx behavior)
  • ✅ 3 new httpx-specific tests added to test_requests_mock_usage.py
  • ✅ All linters pass (pre-commit hooks enforced)

Note

Medium Risk
Moderate risk due to behavioral changes in core test-mocking infrastructure and removal of a public class (MockVWSForHttpx), which may break existing consumers or subtly alter intercept/timeout behavior across HTTP clients.

Overview
Unifies HTTP client mocking so a single MockVWS context manager now intercepts both requests (via responses) and httpx (via respx) at the same time, including support for real_http, base URL path prefixes, and response delay/timeout behavior.

Removes the separate MockVWSForHttpx API from exports and docs, factors MissingSchemeError into _mock_common, and refactors the respx integration into a start_respx_router() helper; tests and documentation/examples are updated accordingly, with new coverage ensuring httpx traffic is intercepted/blocked as expected under MockVWS.

Written by Cursor Bugbot for commit fdfb20a. This will update automatically on new commits. Configure here.

MockVWS now starts both responses (for requests) and respx (for httpx) mocks
simultaneously, eliminating the need for a separate MockVWSForHttpx class.
Removes MockVWSForHttpx entirely. Updates all tests and docs to reflect this change.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Move TYPE_CHECKING guard to after all imports to fix wrong-import-position.
Replace "MockRouter" in docstrings with "respx router" to fix spelling warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

response_delay_seconds=self._response_delay_seconds,
sleep_fn=self._sleep_fn,
real_http=self._real_http,
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responses mock leaked if respx router setup fails

Medium Severity

In __enter__, self._mock.start() is called before start_respx_router(). If start_respx_router raises an exception, __exit__ never runs (the context manager wasn't successfully entered), so the responses mock remains active and silently intercepts all subsequent requests calls. Similarly in __exit__, if self._mock.stop() raises, self._router.stop() is skipped and the respx router stays active. Both resources need try/finally protection since neither cleanup is guaranteed to run if the other fails.

Additional Locations (1)

Fix in Cursor Fix in Web

pyrefly's dual search path ("." and "src") causes the same class to be
seen under two module paths, triggering a spurious bad-argument-type error
when passing API objects to start_respx_router.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tive

Define _APIHandler Protocol in _respx_mock_server/decorators.py so it no
longer imports concrete classes from _requests_mock_server/. This removes
the cross-module dependency that caused pyrefly to see the same class under
two module paths (mock_vws.* vs src.mock_vws.*) and report a spurious
bad-argument-type error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adamtheturtle adamtheturtle merged commit 3df0281 into main Feb 22, 2026
106 checks passed
@adamtheturtle adamtheturtle deleted the adamtheturtle/switch-responses-httpx branch February 22, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant