Skip to content

Skip Sentry in test environments#167

Open
mendral-app[bot] wants to merge 1 commit into
mainfrom
mendral/skip-sentry-in-tests
Open

Skip Sentry in test environments#167
mendral-app[bot] wants to merge 1 commit into
mainfrom
mendral/skip-sentry-in-tests

Conversation

@mendral-app

@mendral-app mendral-app Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Skip Sentry initialization when running in test environments by detecting pytest in sys.modules or BL_TYPE=test environment variable
  • Prevents the sys.settrace hook from capturing test-originated exceptions (like ValueError from incomplete mocks) and sending them to Sentry production

Context

The SDK's custom Sentry integration uses sys.settrace() to capture exceptions from site-packages/blaxel. During CI test runs, this captures errors from test code (e.g., MagicMock objects passing through HTTPStatus()) and reports them to Sentry production. This caused 104 new error groups in the sdk-python@0.2.55 release.

Related insight: Incomplete mock leaks ValueError to Sentry

Changes

  • Added import os to imports in sentry.py
  • Added early return in init_sentry() when:
    • pytest is present in sys.modules (always true during test execution)
    • BL_TYPE environment variable is set to test (set in conftest.py)

Note

Created by Mendral. Tag @mendral-app with feedback or questions.

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.
@mendral-app mendral-app Bot requested a review from a team June 10, 2026 19:59
@mendral-app mendral-app Bot marked this pull request as ready for review June 10, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants