Skip to content

Commit 38575f4

Browse files
test: Add unit test for top-level API set_tags
1 parent 173caea commit 38575f4

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_api.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
from unittest import mock
33

44
from sentry_sdk import (
5+
capture_exception,
56
continue_trace,
67
get_baggage,
78
get_client,
89
get_current_span,
910
get_traceparent,
1011
is_initialized,
1112
start_transaction,
13+
set_tags,
1214
)
1315

1416
from sentry_sdk.client import Client, NonRecordingClient
@@ -135,3 +137,45 @@ def test_get_client():
135137
assert client is not None
136138
assert client.__class__ == NonRecordingClient
137139
assert not client.is_active()
140+
141+
142+
def raise_and_capture():
143+
"""Raise an exception and capture it.
144+
145+
This is a utility function for test_set_tags.
146+
"""
147+
try:
148+
1 / 0
149+
except ZeroDivisionError:
150+
capture_exception()
151+
152+
153+
def test_set_tags(sentry_init, capture_events):
154+
sentry_init()
155+
events = capture_events()
156+
157+
set_tags({"tag1": "value1", "tag2": "value2"})
158+
raise_and_capture()
159+
160+
(*_, event) = events
161+
assert event["tags"] == {"tag1": "value1", "tag2": "value2"}, "Setting tags failed"
162+
163+
set_tags({"tag2": "updated", "tag3": "new"})
164+
raise_and_capture()
165+
166+
(*_, event) = events
167+
assert event["tags"] == {
168+
"tag1": "value1",
169+
"tag2": "updated",
170+
"tag3": "new",
171+
}, "Updating tags failed"
172+
173+
set_tags({})
174+
raise_and_capture()
175+
176+
(*_, event) = events
177+
assert event["tags"] == {
178+
"tag1": "value1",
179+
"tag2": "updated",
180+
"tag3": "new",
181+
}, "Upating tags with empty dict changed tags"

0 commit comments

Comments
 (0)