Fix bentoml tests: remove patch override of mock_http_response, add METRICS assertions#23449
Merged
mwdd146980 merged 1 commit intomasterfrom Apr 23, 2026
Merged
Conversation
…ETRICS assertions
Contributor
Validation ReportAll 20 validations passed. Show details
|
Contributor
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 227485d | Docs | Datadog PR Page | Give us feedback! |
iliakur
approved these changes
Apr 23, 2026
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
Two test correctness bugs in
bentoml/tests/test_unit.py, found during the requests→httpx migration audit (PR #22710).Both tests call
mock_http_response(file_path=...)and then immediately overrideBentomlCheck.httpwithpatch(). The key insight:OpenMetricsScraperhas its ownRequestsWrappercreated independently in__init__, so patchingBentomlCheck.httpnever affected the scraper. Both the scraper and the health endpoint checks ultimately callrequests.Session.get, whichmock_http_responsealready patches.test_bentoml_mock_metricspatch(BentomlCheck.http)block is dead weight.mock_http_responsealready serves health endpoint calls.assert mock_http.get.call_count == 2is an implementation detail assertion that breaks if endpoints are added or removed.test_bentoml_mock_valid_endpoint_invalid_healthApproach
test_bentoml_mock_metrics: Remove the innerpatch()block andassert call_count == 2.test_bentoml_mock_valid_endpoint_invalid_health: Replace withmock_http_response_per_endpointfor explicit URL routing.MockResponse(status_code=500).raise_for_status()raisesHTTPErrornaturally. AddMETRICSassertions.Verification
METRICSassertions totest_bentoml_mock_valid_endpoint_invalid_healthbefore refactoring; confirmed they passed with the old mock (scraper was already emitting metrics correctly).ddev test -fs bentomlclean, 3/3 pass.