Skip to content

Fix bentoml tests: remove patch override of mock_http_response, add METRICS assertions#23449

Merged
mwdd146980 merged 1 commit intomasterfrom
mwdd146980/fix-bentoml-test-patch-overrides-mock
Apr 23, 2026
Merged

Fix bentoml tests: remove patch override of mock_http_response, add METRICS assertions#23449
mwdd146980 merged 1 commit intomasterfrom
mwdd146980/fix-bentoml-test-patch-overrides-mock

Conversation

@mwdd146980
Copy link
Copy Markdown
Contributor

@mwdd146980 mwdd146980 commented Apr 23, 2026

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 override BentomlCheck.http with patch(). The key insight: OpenMetricsScraper has its own RequestsWrapper created independently in __init__, so patching BentomlCheck.http never affected the scraper. Both the scraper and the health endpoint checks ultimately call requests.Session.get, which mock_http_response already patches.

test_bentoml_mock_metrics

  • The inner patch(BentomlCheck.http) block is dead weight. mock_http_response already serves health endpoint calls.
  • assert mock_http.get.call_count == 2 is an implementation detail assertion that breaks if endpoints are added or removed.

test_bentoml_mock_valid_endpoint_invalid_health

  • Achieves URL routing by accident via two independent mock layers that happen to target different code paths.
  • No assertions on OpenMetrics metrics, so a regression in the primary check output would go undetected.

Approach

  • test_bentoml_mock_metrics: Remove the inner patch() block and assert call_count == 2.
  • test_bentoml_mock_valid_endpoint_invalid_health: Replace with mock_http_response_per_endpoint for explicit URL routing. MockResponse(status_code=500).raise_for_status() raises HTTPError naturally. Add METRICS assertions.

Verification

  • Added METRICS assertions to test_bentoml_mock_valid_endpoint_invalid_health before refactoring; confirmed they passed with the old mock (scraper was already emitting metrics correctly).
  • ddev test -fs bentoml clean, 3/3 pass.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Apr 23, 2026

Validation Report

All 20 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and Codecov settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

@mwdd146980 mwdd146980 self-assigned this Apr 23, 2026
@datadog-datadog-prod-us1
Copy link
Copy Markdown
Contributor

datadog-datadog-prod-us1 Bot commented Apr 23, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 94.79% (+7.72%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 227485d | Docs | Datadog PR Page | Give us feedback!

@mwdd146980 mwdd146980 marked this pull request as ready for review April 23, 2026 15:28
@mwdd146980 mwdd146980 requested a review from a team as a code owner April 23, 2026 15:28
@mwdd146980 mwdd146980 added this pull request to the merge queue Apr 23, 2026
Merged via the queue into master with commit 428fab2 Apr 23, 2026
49 of 56 checks passed
@mwdd146980 mwdd146980 deleted the mwdd146980/fix-bentoml-test-patch-overrides-mock branch April 23, 2026 16:00
@dd-octo-sts dd-octo-sts Bot added this to the 7.79.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants