forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
42 lines (28 loc) · 985 Bytes
/
test_api.py
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
from sentry_sdk import (
configure_scope,
get_current_span,
start_transaction,
)
try:
from unittest import mock # python 3.3 and above
except ImportError:
import mock # python < 3.3
def test_get_current_span():
fake_hub = mock.MagicMock()
fake_hub.scope = mock.MagicMock()
fake_hub.scope.span = mock.MagicMock()
assert get_current_span(fake_hub) == fake_hub.scope.span
fake_hub.scope.span = None
assert get_current_span(fake_hub) is None
def test_get_current_span_default_hub(sentry_init):
sentry_init()
assert get_current_span() is None
with configure_scope() as scope:
fake_span = mock.MagicMock()
scope.span = fake_span
assert get_current_span() == fake_span
def test_get_current_span_default_hub_with_transaction(sentry_init):
sentry_init()
assert get_current_span() is None
with start_transaction() as new_transaction:
assert get_current_span() == new_transaction