Skip to content

Commit f3e8a5c

Browse files
authored
fix(tests): Don't assume release is set (#4879)
### Description Even though we try to figure out the current release automatically if it's not provided, it can still end up being `None`. If that's the case, it won't be attached to logs. The `test_logs_attributes` test assumes there always is a release, which is incorrect. I opted for conditionally checking for `sentry.release` in the test instead of removing the check altogether, even though the test itself is supposed to test custom user provided attributes. The reason is that there is no other generic logs test testing `sentry.release`. #### Issues Closes #4878 #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr)
1 parent ffc88f5 commit f3e8a5c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tests/test_logs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def test_logs_attributes(sentry_init, capture_envelopes):
230230
for k, v in attrs.items():
231231
assert logs[0]["attributes"][k] == v
232232
assert logs[0]["attributes"]["sentry.environment"] == "production"
233-
assert "sentry.release" in logs[0]["attributes"]
233+
if sentry_sdk.get_client().options.get("release") is not None:
234+
assert "sentry.release" in logs[0]["attributes"]
234235
assert logs[0]["attributes"]["sentry.message.parameter.my_var"] == "some value"
235236
assert logs[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server"
236237
assert logs[0]["attributes"]["sentry.sdk.name"].startswith("sentry.python")

0 commit comments

Comments
 (0)