Skip to content

Commit 7472d5f

Browse files
committed
Cleaned up tests
1 parent cccce0f commit 7472d5f

File tree

1 file changed

+4
-64
lines changed

1 file changed

+4
-64
lines changed

tests/test_logs.py

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def _before_log(record, hint):
6060
return record
6161

6262
sentry_init(
63-
enable_sentry_logs=True,
64-
before_emit_log=_before_log,
63+
_experiments={
64+
"enable_sentry_logs": True,
65+
"before_emit_log": _before_log,
66+
}
6567
)
6668
envelopes = capture_envelopes()
6769

@@ -133,68 +135,6 @@ def test_logs_message_params(sentry_init, capture_envelopes):
133135
assert envelopes[3].items[0].payload.json["attributes"][-1] == {"key": "sentry.message.parameters.string_var", "value": {'stringValue': "some string value"}}
134136

135137

136-
def test_logs_message_old_style(sentry_init, capture_envelopes):
137-
"""
138-
This is how vars are passed to strings in old Python projects.
139-
TODO: Should we support this?
140-
"""
141-
sentry_init(_experiments={"enable_sentry_logs": True})
142-
143-
envelopes = capture_envelopes()
144-
145-
sentry_logger.warn("The recorded value was '%s'" % 1)
146-
147-
assert envelopes[0].items[0].payload.json["body"]["stringValue"] == "The recorded value was '1'"
148-
assert envelopes[0].items[0].payload.json["attributes"][-1] == {"key": "sentry.release", "value": {"stringValue": mock.ANY}} # no parametrization!
149-
150-
151-
def test_logs_message_format(sentry_init, capture_envelopes):
152-
"""
153-
This is another popular way how vars are passed to strings in old Python projects.
154-
TODO: Should we support this?
155-
"""
156-
sentry_init(_experiments={"enable_sentry_logs": True})
157-
envelopes = capture_envelopes()
158-
159-
sentry_logger.warn("The recorded value was '{int_var}'".format(int_var=1))
160-
161-
assert envelopes[0].items[0].payload.json["body"]["stringValue"] == "The recorded value was '1'"
162-
assert envelopes[0].items[0].payload.json["attributes"][-1] == {"key": "sentry.release", "value": {"stringValue": mock.ANY}} # no parametrization!
163-
164-
165-
def test_logs_message_f_string(sentry_init, capture_envelopes):
166-
"""
167-
This is the preferred way how vars are passed to strings in newer Python projects.
168-
TODO: This we should definitely support.
169-
"""
170-
sentry_init(_experiments={"enable_sentry_logs": True})
171-
envelopes = capture_envelopes()
172-
173-
int_var = 1
174-
sentry_logger.warn(f"The recorded value was '{int_var}'")
175-
176-
assert envelopes[0].items[0].payload.json["body"]["stringValue"] == "The recorded value was '1'"
177-
assert envelopes[0].items[0].payload.json["attributes"][-1] == {"key": "sentry.release", "value": {"stringValue": mock.ANY}} # no parametrization!
178-
179-
180-
def test_logs_message_python_logging(sentry_init, capture_envelopes):
181-
"""
182-
This is how vars are passed to log messages when using Python logging module.
183-
TODO: We probably should also support this, to make it easier to migrate from the old logging module to the Sentry one.
184-
"""
185-
sentry_init(_experiments={"enable_sentry_logs": True})
186-
envelopes = capture_envelopes()
187-
188-
try:
189-
sentry_logger.warn(f"The recorded value was '%s'", 1)
190-
except Exception as ex:
191-
# This is when users just replace the existing call to Python logging method, with the new Sentry logging method.
192-
# This is a very confusing error message to explain what is wrong here.
193-
assert str(ex) == "capture_log() takes 3 positional arguments but 4 were given"
194-
195-
assert len(envelopes) == 0
196-
197-
198138
def test_logs_tied_to_transactions(sentry_init, capture_envelopes):
199139
"""
200140
Log messages are also tied to transactions.

0 commit comments

Comments
 (0)