1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import pytest
from sentry_sdk.integrations.serverless import serverless_function
def test_basic(sentry_init, capture_exceptions, monkeypatch):
sentry_init()
exceptions = capture_exceptions()
flush_calls = []
@serverless_function
def foo():
monkeypatch.setattr("sentry_sdk.flush", lambda: flush_calls.append(1))
1 / 0
with pytest.raises(ZeroDivisionError):
foo()
(exception,) = exceptions
assert isinstance(exception, ZeroDivisionError)
assert flush_calls == [1]
def test_flush_disabled(sentry_init, capture_exceptions, monkeypatch):
sentry_init()
exceptions = capture_exceptions()
flush_calls = []
monkeypatch.setattr("sentry_sdk.flush", lambda: flush_calls.append(1))
@serverless_function(flush=False)
def foo():
1 / 0
with pytest.raises(ZeroDivisionError):
foo()
(exception,) = exceptions
assert isinstance(exception, ZeroDivisionError)
assert flush_calls == []
|