From 4820b15970317d049b07e23638777d80d04fda0b 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:59:27 -0700 Subject: [PATCH] fix: skip Sentry initialization in test environments Add early return in init_sentry() when pytest is detected in sys.modules or BL_TYPE=test environment variable is set. This prevents the sys.settrace hook from capturing test-originated exceptions and sending them to Sentry production. --- src/blaxel/core/common/sentry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/blaxel/core/common/sentry.py b/src/blaxel/core/common/sentry.py index d2538820..048dd5c0 100644 --- a/src/blaxel/core/common/sentry.py +++ b/src/blaxel/core/common/sentry.py @@ -1,6 +1,7 @@ import atexit import json import logging +import os import sys import threading import traceback @@ -231,6 +232,10 @@ def init_sentry() -> None: """Initialize the lightweight Sentry client for SDK error tracking.""" global _sentry_initialized, _sentry_config, _handlers_registered try: + # Don't initialize in test environments + if "pytest" in sys.modules or os.environ.get("BL_TYPE") == "test": + return + dsn = settings.sentry_dsn if not dsn: return