Remove requests.Session test patches from conftest.py files#23314
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:
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 8a139cc | Docs | Datadog PR Page | Give us feedback! |
14387fd to
33ed764
Compare
4cbf0d3 to
39292db
Compare
33ed764 to
e310970
Compare
14a4779 to
3bc04d2
Compare
e310970 to
c22010a
Compare
Replace requests.Session.get patches with mock_http fixture for 4 OpenMetricsBaseCheckV2 integrations. MockHTTPResponse natively supports iter_lines() and content, removing the need for MagicMock wrappers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace mocker.patch('requests.Session.get') with mock_http fixture.
Replace all mocker.Mock() responses with MockHTTPResponse(json_data=...).
107 unit tests pass; 10+ URL handlers with pagination and time-based
filtering preserved unchanged.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the requests.Session.get patch from yarn conftest.py. Convert test_ssl_verification from an end-to-end SSL behavior test to a config assertion test that verifies ssl_verify propagates to http.options['verify']. Remove unused mock/patch/SSLError imports. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Change get_http_handler() in both openmetrics/mixins.py and prometheus/mixins.py to return self.http instead of constructing a new RequestsWrapper, allowing mock_http to intercept v1 mixin HTTP calls. Migrate 8 conftest.py files from requests.Session patches to mock_http + MockHTTPResponse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The production mixin change (returning self.http from get_http_handler) broke kubelet's per-endpoint TLS isolation and prometheus E2E tests. Revert to RequestsWrapper construction in production. Instead, patch get_http_handler directly in each conftest fixture via mocker.patch to return mock_http — same decoupling result, zero production risk. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add mock_openmetrics_http and mock_prometheus_http to pytest plugin, centralizing the get_http_handler patch in one place - Update 7 conftest files to use mock_openmetrics_http, 1 to use mock_prometheus_http (eliminates repeated magic string) - Remove unnecessary get_http_handler patch from 3 haproxy fixtures (legacy check uses self.http.get directly, not the OM mixin) - Fix gitlab version endpoint: json_data=json.loads(text_data) so .json() returns a dict instead of a string (pre-existing bug) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Rewrite 8 nutanix test_retry.py tests to use mock_http_get instead of dead requests.Session.get patches (MockHTTPResponse + HTTPStatusError) - Update changelog to include mock_openmetrics_http/mock_prometheus_http - Remove unreachable /-/health duplicate in gitlab conftest Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9709aed to
7e8968a
Compare
362e3dd to
573ae6c
Compare
Replaces test_tls_verify_config_propagates with test_ssl_verification. Two-phase test mirrors original shape: SSLError -> CRITICAL service check, then verify=False -> 4 OK service checks. Uses mock_http instead of patching requests.Session. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Restore original try/except/else body. Only diff vs pre-migration: fixture arg (mocked_bad_cert_request -> mock_http) and side_effect setup lines. No pytest.raises rewrite. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment removal was out of scope for this PR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Validation ReportAll 20 validations passed. Show details
|
242c4ad
into
mwdd146980/httpx-migration-base

Motivation
Test fixtures that patch
requests.Sessiondirectly will silently break when integrations switch fromrequeststohttpx. Themock_httpfixture intercepts HTTP at theAgentCheck.httplevel, making tests transport-agnostic.Approach
mocker.patch('requests.Session.get', ...)withmock_httpfixture +MockHTTPResponse.get_http_handler()constructs its ownRequestsWrapper, bypassingself.http. Fixtures patchget_http_handlerviamocker.patchto returnmock_http. No production code changes. Shared fixturesmock_openmetrics_http/mock_prometheus_httpextracted to the ddev pytest plugin.Notable changes
conftest.py,mock_http_getwas rewritten to dispatch URLs viaMockHTTPResponseinstead of buildingmocker.Mock(spec=Response)per branch.test_ssl_verification: Old test assertedrequests-library SSL behavior (raisesSSLErroron bad cert), which is already covered indatadog_checks_base/tests/. Themocked_bad_cert_requestfixture was removed.haproxy_mock,haproxy_mock_evil, andhaproxy_mock_enterprise_version_infofromscope="module"to function scope, sincemock_httpis function-scoped and pytest forbids broader-scoped fixtures from depending on narrower ones. These are mock-config fixtures only so runtime impact is negligible.Verification
All target integrations pass. Cilium has 2 pre-existing legacy test failures (confirmed on clean branch).