From a2b8df0a6a0aac235c11bf45df1854bdf56a4cd7 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 6 Mar 2025 23:45:48 +0100 Subject: [PATCH] Use Sentry helper function to report warnings (#5734) * Use Sentry helper function to report warnings Don't use Sentry directly but the existing helper function. * Add pytest that Sentry is by default off * Address ruff * Address ruff --- supervisor/bootstrap.py | 3 +-- tests/utils/test_sentry.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/utils/test_sentry.py diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index b2f40a980..5275f8fd5 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -8,7 +8,6 @@ import signal import warnings from colorlog import ColoredFormatter -from sentry_sdk import capture_exception from .addons.manager import AddonManager from .api import RestAPI @@ -46,7 +45,7 @@ from .services import ServiceManager from .store import StoreManager from .supervisor import Supervisor from .updater import Updater -from .utils.sentry import init_sentry +from .utils.sentry import capture_exception, init_sentry _LOGGER: logging.Logger = logging.getLogger(__name__) diff --git a/tests/utils/test_sentry.py b/tests/utils/test_sentry.py new file mode 100644 index 000000000..ff7982af9 --- /dev/null +++ b/tests/utils/test_sentry.py @@ -0,0 +1,15 @@ +"""Unit tests for Sentry.""" + +from unittest.mock import patch + +from supervisor.bootstrap import initialize_coresys + + +async def test_sentry_disabled_by_default(supervisor_name): + """Test diagnostics off by default.""" + with ( + patch("supervisor.bootstrap.initialize_system"), + patch("sentry_sdk.init") as sentry_init, + ): + await initialize_coresys() + sentry_init.assert_not_called()