Decouple integration tests from the requests library#24602
Draft
mwdd146980 wants to merge 9 commits into
Draft
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
conftest.py's mock_http_call, mock_auth, and mock_http_get fixtures patched requests.Session directly, coupling tests to the requests backend. Route them through the auto-available mock_http fixture and agnostic MockHTTPResponse/HTTPStatusError instead.
Five tests patched requests.Session.get/post directly and imported requests.exceptions. Swap them onto the mock_http fixture and the agnostic http_exceptions module so the suite no longer depends on requests.
Contributor
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 584399c | Docs | Datadog PR Page | Give us feedback! |
Contributor
Validation Report
Run Passed validations (20)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes hardcoded
requestslibrary coupling from the test suites of seven integrations, so the tests keep working when the HTTP backend swaps fromrequeststohttpx. Each test is moved onto a sanctioned, backend-agnostic seam:mock_http(patches theAgentCheck.httpproperty) for checks that callself.httpdirectly.mock_http_response/mock_http_response_per_endpoint(the single central_DEFAULT_MOCK_METHODseam) for OpenMetrics and response-body cases.datadog_checks.base.utils.http_exceptionsin place ofrequests.exceptions.*.Integrations touched: crio, flink, nginx_ingress_controller, nginx (VTS), silk, http_check, nvidia_nim, dell_powerflex. This is a test-only change: no production code and no changelog entries.
Motivation
Tests that hardcode
mock.patch('requests.Session.get'/'.post'/'.request'), import fromrequests.exceptions, or patchrequests.Response.jsonbypass the sanctioned fixtures and would break silently once the backend is no longerrequests. Centralizing them on the agnostic fixtures/exceptions makes the eventual httpx cutover a single-seam change instead of a scattered one. Stacked on #24516.Out of scope: kube_* (already migrated by the catch-narrowing branch), and vsphere / openstack_controller (blocked on their production HTTP migration).
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged