Skip to content

Commit 427f2dd

Browse files
committed
Removed hub from session tests
1 parent 1def184 commit 427f2dd

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

tests/test_sessions.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest import mock
22

33
import sentry_sdk
4-
from sentry_sdk import Hub
54
from sentry_sdk.sessions import auto_session_tracking
65

76

@@ -15,17 +14,17 @@ def test_basic(sentry_init, capture_envelopes):
1514
sentry_init(release="fun-release", environment="not-fun-env")
1615
envelopes = capture_envelopes()
1716

18-
hub = Hub.current
19-
hub.start_session()
17+
sentry_sdk.Scope.get_isolation_scope().start_session()
2018

2119
try:
22-
with hub.configure_scope() as scope:
23-
scope.set_user({"id": "42"})
24-
raise Exception("all is wrong")
20+
scope = sentry_sdk.Scope.get_current_scope()
21+
scope.set_user({"id": "42"})
22+
raise Exception("all is wrong")
2523
except Exception:
26-
hub.capture_exception()
27-
hub.end_session()
28-
hub.flush()
24+
sentry_sdk.capture_exception()
25+
26+
sentry_sdk.Scope.get_isolation_scope().end_session()
27+
sentry_sdk.flush()
2928

3029
assert len(envelopes) == 2
3130
assert envelopes[0].get_event() is not None
@@ -51,22 +50,20 @@ def test_aggregates(sentry_init, capture_envelopes):
5150
)
5251
envelopes = capture_envelopes()
5352

54-
hub = Hub.current
55-
5653
with auto_session_tracking(session_mode="request"):
5754
with sentry_sdk.push_scope():
5855
try:
59-
with sentry_sdk.configure_scope() as scope:
60-
scope.set_user({"id": "42"})
61-
raise Exception("all is wrong")
56+
scope = sentry_sdk.Scope.get_current_scope()
57+
scope.set_user({"id": "42"})
58+
raise Exception("all is wrong")
6259
except Exception:
6360
sentry_sdk.capture_exception()
6461

6562
with auto_session_tracking(session_mode="request"):
6663
pass
6764

68-
hub.start_session(session_mode="request")
69-
hub.end_session()
65+
sentry_sdk.Scope.get_isolation_scope().start_session(session_mode="request")
66+
sentry_sdk.Scope.get_isolation_scope().end_session()
7067

7168
sentry_sdk.flush()
7269

@@ -95,8 +92,6 @@ def test_aggregates_explicitly_disabled_session_tracking_request_mode(
9592
)
9693
envelopes = capture_envelopes()
9794

98-
hub = Hub.current
99-
10095
with auto_session_tracking(session_mode="request"):
10196
with sentry_sdk.push_scope():
10297
try:
@@ -107,8 +102,8 @@ def test_aggregates_explicitly_disabled_session_tracking_request_mode(
107102
with auto_session_tracking(session_mode="request"):
108103
pass
109104

110-
hub.start_session(session_mode="request")
111-
hub.end_session()
105+
sentry_sdk.Scope.get_isolation_scope().start_session(session_mode="request")
106+
sentry_sdk.Scope.get_isolation_scope().end_session()
112107

113108
sentry_sdk.flush()
114109

@@ -128,8 +123,6 @@ def test_no_thread_on_shutdown_no_errors(sentry_init):
128123
environment="not-fun-env",
129124
)
130125

131-
hub = Hub.current
132-
133126
# make it seem like the interpreter is shutting down
134127
with mock.patch(
135128
"threading.Thread.start",
@@ -145,7 +138,6 @@ def test_no_thread_on_shutdown_no_errors(sentry_init):
145138
with auto_session_tracking(session_mode="request"):
146139
pass
147140

148-
hub.start_session(session_mode="request")
149-
hub.end_session()
150-
141+
sentry_sdk.Scope.get_isolation_scope().start_session(session_mode="request")
142+
sentry_sdk.Scope.get_isolation_scope().end_session()
151143
sentry_sdk.flush()

0 commit comments

Comments
 (0)