"""Test main method.""" import logging from typing import Any from unittest.mock import MagicMock, patch import pytest from m2mconfig import config from m2mconfig.cli.main import setup @pytest.mark.parametrize( "sentry_env_value", [ pytest.param( None, id="sentry should not be initialized when the SENTRY env is not defined.", ), pytest.param( "no.such.dsn", id="sentry should be initialized when the SENTRY env is defined.", ), ], ) @patch("m2mconfig.cli.main.sentry_sdk") @patch("m2mconfig.cli.main.configure_logging") def test_setup( mock_configure_logging: MagicMock, sentry_sdk: MagicMock, monkeypatch: Any, caplog: pytest.LogCaptureFixture, sentry_env_value: str | None, ) -> None: """Test the setup method.""" monkeypatch.setattr(config, "SENTRY", sentry_env_value) caplog.set_level(logging.INFO) setup() mock_configure_logging.assert_called() if sentry_env_value: sentry_sdk.init.assert_called() assert "SENTRY enabled" in caplog.text else: sentry_sdk.init.assert_not_called() assert "SENTRY disabled" in caplog.text