Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix non-idempotent test #3253

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all 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
36 changes: 22 additions & 14 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tests.conftest import patch_start_tracing_child

import sentry_sdk
import sentry_sdk.scope
from sentry_sdk import (
push_scope,
configure_scope,
Expand All @@ -29,10 +30,7 @@
)
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.scope import ( # noqa: F401
add_global_event_processor,
global_event_processors,
)
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.utils import get_sdk_name, reraise
from sentry_sdk.tracing_utils import has_tracing_enabled

Expand Down Expand Up @@ -581,21 +579,31 @@ def test_event_processor_drop_records_client_report(
events = capture_events()
reports = capture_client_reports()

global global_event_processors
# Ensure full idempotency by restoring the original global event processors list object, not just a copy.
old_processors = sentry_sdk.scope.global_event_processors

@add_global_event_processor
def foo(event, hint):
return None
try:
sentry_sdk.scope.global_event_processors = (
sentry_sdk.scope.global_event_processors.copy()
)

capture_message("dropped")
@add_global_event_processor
def foo(event, hint):
return None

with start_transaction(name="dropped"):
pass
capture_message("dropped")

assert len(events) == 0
assert reports == [("event_processor", "error"), ("event_processor", "transaction")]
with start_transaction(name="dropped"):
pass

assert len(events) == 0
assert reports == [
("event_processor", "error"),
("event_processor", "transaction"),
]

global_event_processors.pop()
finally:
sentry_sdk.scope.global_event_processors = old_processors


@pytest.mark.parametrize(
Expand Down
Loading