Make MockVWS intercept both requests and httpx#2998
Conversation
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>
There was a problem hiding this comment.
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, | ||
| ) |
There was a problem hiding this comment.
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)
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>


Summary
requests(viaresponses) andhttpx(viarespx) simultaneouslyMockVWSclass handles both HTTP librariesTest plan
test_requests_mock_usage.pyNote
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
MockVWScontext manager now intercepts bothrequests(viaresponses) andhttpx(viarespx) at the same time, including support forreal_http, base URL path prefixes, and response delay/timeout behavior.Removes the separate
MockVWSForHttpxAPI from exports and docs, factorsMissingSchemeErrorinto_mock_common, and refactors therespxintegration into astart_respx_router()helper; tests and documentation/examples are updated accordingly, with new coverage ensuringhttpxtraffic is intercepted/blocked as expected underMockVWS.Written by Cursor Bugbot for commit fdfb20a. This will update automatically on new commits. Configure here.