Add mock_http fixture; migrate 9 intg to mock_http#22710
Add mock_http fixture; migrate 9 intg to mock_http#22710mwdd146980 merged 20 commits intomwdd146980/httpx-migration-basefrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report❌ Patch coverage is Additional details and impacted files🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
Patches get/post/put/delete/head/patch on RequestsWrapper so all three HTTP paths are intercepted: AgentCheck.http, OpenMetrics V2 scraper, and kube* health check handlers. Real RequestsWrapper instances are still created, so check.http.options remains accessible. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace direct mock.patch('requests.Session.get') with the library-agnostic
mock_http fixture and MockHTTPResponse from http_testing.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…xture
Replace direct mocker.patch('requests.Session.get') with the library-agnostic
mock_http fixture and MockHTTPResponse from http_testing.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…fixture
Replace direct mocker.patch('requests.Session.get') with the library-agnostic
mock_http fixture and MockHTTPResponse from http_testing.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The fixture mocks the HTTP client (RequestsWrapper), not responses. mock_http_client is more precise and avoids confusion with the existing mock_http_response fixture from datadog_checks.dev. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… fixture
Replace direct mocker.patch('requests.Session.get') with the library-agnostic
mock_http_client fixture and MockHTTPResponse from http_testing.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ent fixture
Replace direct mocker.patch('requests.Session.get') with the library-agnostic
mock_http_client fixture and MockHTTPResponse from http_testing.py.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use direct import with noqa: F401 to match the existing codebase pattern. No other integration uses pytest_plugins for fixture registration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The fixture name mock_http_client was added in the previous commit, but the team prefers the shorter mock_http name. Revert all usages across integrations and the fixture definition in http_testing.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…yMock on AgentCheck.http - mock_http now patches AgentCheck.http via PropertyMock with a create_autospec(HTTPClientProtocol) client, constraining the mock to the protocol interface and enforcing call signatures - AgentCheck.http return type updated from RequestsWrapper to HTTPClientProtocol - OM V2 scraper reuses check.http directly instead of constructing its own RequestsWrapper; options access guarded with hasattr for mock compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mock_http fixture Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
base_scraper.py shares check.http via `self.http = check.http`. The previous code mutated `self.http.options['headers']['Accept']` which bled through to check.http since they are the same object, breaking tests that assert check.http.options['headers']['Accept'] == '*/*'. Fix: store the accept header as self._accept_header and inject it per-request via extra_headers in send_request. Using extra_headers (not headers=) is required because RequestsWrapper._request uses ChainMap — passing headers= directly would shadow the entire session headers dict rather than merging a single key. Update test assertions in three files to check scraper._accept_header instead of scraper.http.options['headers']['Accept']. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
After self.http = check.http in the OM V2 scraper, patching
BentomlCheck.http at the class level intercepted scraper HTTP calls too,
causing AttributeError on the minimal mock response. Replace both
patch('BentomlCheck.http') blocks with URL-based dispatch on the
already-patched requests.Session.get mock.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| aggregator.assert_metric_has_tag('bentoml.service.request.count', 'bentoml_endpoint:/summarize') | ||
| aggregator.assert_service_check('bentoml.openmetrics.health', ServiceCheck.OK) | ||
| aggregator.assert_all_metrics_covered() | ||
| assert get_mock.call_count == 3 # 1 metrics scrape + 2 health endpoints (/livez, /readyz) |
There was a problem hiding this comment.
| assert get_mock.call_count == 3 # 1 metrics scrape + 2 health endpoints (/livez, /readyz) |
Asserting this would tie us to the implementation.
IMO: What our users see are metrics and health checks, those are the things we should ensure our code is doing, testing the code itself will only require us to update the tests for every change in the code, even if it doesn't change any output or observed behavior. This is similar to the black-box testing concept.
There was a problem hiding this comment.
Applied suggestion.
Asserting on the number of HTTP calls ties the test to implementation details rather than observable behavior (metrics, service checks). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Test Decoupling Step 1 (plan). Stacked on #22676.
Adds the
mock_httppytest fixture and migrates 9 integration test suites to library-agnostic HTTP mocking. The OM V2 scraper is also refactored to reusecheck.httpinstead of constructing its ownRequestsWrapper, which uncovered two bugs fixed here:Acceptheader was being mutated into the sharedcheck.http.optionsdict; fixed by injecting it viaextra_headersper-requestX-Vault-Token,X-Vault-Request) needed to be reapplied tocheck.httpinconfigure_scrapersafter the scraper started sharing itchecks/base.pyAgentCheck.httpreturn type:RequestsWrapper→HTTPClientProtocolchecks/openmetrics/v2/scraper/base_scraper.pycheck.http;Acceptheader injected viaextra_headersutils/http_testing.pyMockHTTPResponse.json_data: type widened toAnyplugin/pytest.pymock_httpfixture addedIntegration tests migrated: falco, strimzi, couchbase, ray, tekton, kubevirt_api, kubevirt_controller, kubevirt_handler, bentoml
Review checklist (to be filled by reviewers)
qa/skip-qalabel if the PR doesn't need to be tested during QA.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged