Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions tests/integrations/loguru/test_loguru.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import MagicMock, patch
import re

import pytest
from loguru import logger
Expand Down Expand Up @@ -56,10 +57,10 @@ def test_just_log(

getattr(logger, level.name.lower())("test")

formatted_message = (
" | "
+ "{:9}".format(level.name.upper())
+ "| tests.integrations.loguru.test_loguru:test_just_log:57 - test"
expected_pattern = (
r" \| "
+ r"{:9}".format(level.name.upper())
+ r"\| tests\.integrations\.loguru\.test_loguru:test_just_log:\d+ - test"
)

if not created_event:
Expand All @@ -72,7 +73,8 @@ def test_just_log(
(breadcrumb,) = breadcrumbs
assert breadcrumb["level"] == expected_sentry_level
assert breadcrumb["category"] == "tests.integrations.loguru.test_loguru"
assert breadcrumb["message"][23:] == formatted_message
# Check that the message matches the expected pattern with a line number
assert re.search(expected_pattern, breadcrumb["message"][23:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we want to use fullmatch rather than search. With search, the assertion passes if the string contains something matching the regex, but here, we instead want to ensure that the entire string matches

else:
assert not breadcrumbs

Expand All @@ -85,7 +87,8 @@ def test_just_log(
(event,) = events
assert event["level"] == expected_sentry_level
assert event["logger"] == "tests.integrations.loguru.test_loguru"
assert event["logentry"]["message"][23:] == formatted_message
# Check that the message matches the expected pattern with a line number
assert re.search(expected_pattern, event["logentry"]["message"][23:])


def test_breadcrumb_format(sentry_init, capture_events, uninstall_integration, request):
Expand Down
Loading