From ee6ca42c296c27ac33b7d00956b0eb1840608085 Mon Sep 17 00:00:00 2001 From: "mendral-app[bot]" <233154221+mendral-app[bot]@users.noreply.github.com> Date: Wed, 10 Jun 2026 12:57:52 -0700 Subject: [PATCH] fix: configure mock_client fixture with integer status_code defaults The mock_client fixture yielded a bare MagicMock, so any test code reaching client.get_httpx_client().request().status_code would get another MagicMock instead of an integer. The auto-generated API client code calls HTTPStatus(response.status_code), which raises ValueError on non-integer input. These errors were then reported to the production Sentry project because BL_ENV defaulted to 'prod' during test runs. Changes: - Pre-configure get_httpx_client().request() and get_async_httpx_client().request() return values with status_code=200 and sensible defaults for content, headers, and json() - Set BL_ENV=test in the session-scoped test environment fixture to prevent Sentry initialization during tests (init_sentry skips environments other than dev/prod) --- tests/conftest.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 368dc779..2eaee27f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ import os from pathlib import Path -from unittest.mock import patch +from unittest.mock import MagicMock, patch import pytest from dotenv import load_dotenv @@ -20,6 +20,7 @@ def setup_test_environment(): "BL_WORKSPACE": "test-workspace", "BL_TYPE": "test", "BL_NAME": "test-component", + "BL_ENV": "test", "BL_DEBUG_TELEMETRY": "false", "BL_ENABLE_OPENTELEMETRY": "false", } @@ -42,8 +43,29 @@ def setup_test_environment(): @pytest.fixture def mock_client(): - """Mock the Blaxel client.""" + """Mock the Blaxel client. + + Pre-configures get_httpx_client().request() and get_async_httpx_client().request() + to return responses with integer status_code values, preventing ValueError when + auto-generated API code calls HTTPStatus(response.status_code). + """ with patch("blaxel.core.client.client") as mock: + # Configure default response for sync httpx client + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.content = b"{}" + mock_response.headers = {} + mock_response.json.return_value = {} + mock.get_httpx_client.return_value.request.return_value = mock_response + + # Configure default response for async httpx client + mock_async_response = MagicMock() + mock_async_response.status_code = 200 + mock_async_response.content = b"{}" + mock_async_response.headers = {} + mock_async_response.json.return_value = {} + mock.get_async_httpx_client.return_value.request.return_value = mock_async_response + yield mock