Migrate vault tests to mock_http fixture#23557
Draft
mwdd146980 wants to merge 1 commit intomwdd146980/httpx-migration-basefrom
Draft
Migrate vault tests to mock_http fixture#23557mwdd146980 wants to merge 1 commit intomwdd146980/httpx-migration-basefrom
mwdd146980 wants to merge 1 commit intomwdd146980/httpx-migration-basefrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 99d05c1 | Docs | Datadog PR Page | Give us feedback! |
Base automatically changed from
mwdd146980/step4-conftest-session-patches
to
mwdd146980/httpx-migration-base
May 1, 2026 15:59
e048f71 to
e49be69
Compare
e49be69 to
99d05c1
Compare
Contributor
Validation ReportAll 20 validations passed. Show details
|
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.
Motivation
Step 5.3 of the httpx migration: remove the last
mock.patch('requests.Session.*')patches fromvault/tests/test_vault.pyso the suite no longer depends on the requests transport layer.Approach
All 17 sites in
vault/tests/test_vault.pyroute through themock_http/mock_openmetrics_httpfixtures plusMockHTTPResponse:with mock.patch('requests.Session.get', side_effect=fn, autospec=True):becomesmock_http.get.side_effect = fnafter stripping the autospec-injectedsessionarg from eachmock_requests_get.test_service_check_500_fail) —mock.patch(..., return_value=...)becomesmock_http.get.return_value = MockHTTPResponse(status_code=500).test_x_vault_request_header_is_set) — rewritten to assertmock_openmetrics_http.options['headers']['X-Vault-Request'] == 'true'rather than peeking at outbound transportheaders=kwargs. This is the right layer: vault attachesX-Vault-Requestto its HTTP wrapper; wrapper→transport propagation is unit-tested upstream indatadog_checks_base/tests/base/utils/http/test_headers.py. Sets the precedent for Step 6/7 wrapper-header tests.The stateful
getattr(fn, 'first_health_call', True)toggle intest_replication_dr_mode_changedis preserved as-is —unittest.mockside_effectcallables relay calls verbatim, function attributes are unaffected.OM-v1 and OM-v2 X-Vault-Request header sites: OM-v2 sets the header in
__init__(covered automatically); OM-v1 sets it inparse_config(called explicitly in the test).Verification
ddev test -fs vault— cleanddev --no-interactive test vault— 64 passed, 14 skipped (auth-only)rg "requests\.Session" vault/tests/test_vault.py— zero matchesTest plan
requests.Sessionpatches remainuse_openmetricsparametrize variants oftest_x_vault_request_header_is_setpass