"""Lambda test module.""" import pytest from src.utils import exceptions @pytest.mark.parametrize( 'exc_cls, expected_to_capture', ( # Expected to capture Exception instances: (ValueError, True), (ZeroDivisionError, True), (Exception, True), # Expected not to capture anything else: (KeyboardInterrupt, False), (SystemExit, False), ) ) def test_sentry_capture_exception(exc_cls, expected_to_capture, mocker): """Test decorator sending errors to Sentry on exception.""" @exceptions.sentry_capture_exception def func_that_raises(): raise exc_cls() mock_sentry_client = mocker.patch('src.utils.exceptions.capture_exception') mock_logger = mocker.patch('src.utils.exceptions.logging.logger') with pytest.raises(exc_cls): func_that_raises() assert mock_sentry_client.called is expected_to_capture assert mock_logger.exception.call_count == int(expected_to_capture) def test_sentry_capture_exception_noop(mocker): """Test decorator not modifying return value on successful execution.""" @exceptions.sentry_capture_exception def func_that_does_not_raise(): return True mock_sentry_client = mocker.patch('src.utils.exceptions.capture_exception') mock_logger = mocker.patch('src.utils.exceptions.logging.logger') assert func_that_does_not_raise() is True assert mock_sentry_client.called is False assert mock_logger.exception.call_count == 0