Skip to content

fix(tests): Reset flusher isolation scope level to fix test pollution#109007

Closed
joshuarli wants to merge 1 commit intomasterfrom
fix/test-pollution-flusher-scope-leak-108908
Closed

fix(tests): Reset flusher isolation scope level to fix test pollution#109007
joshuarli wants to merge 1 commit intomasterfrom
fix/test-pollution-flusher-scope-leak-108908

Conversation

@joshuarli
Copy link
Copy Markdown
Member

Summary

  • The span consumer flusher thread sets scope.level = "warning" on the sentry_sdk isolation scope. In tests, the flusher runs as a thread (not a subprocess), so this modification leaks into subsequent tests.
  • Wrap test body in try/finally to ensure flusher cleanup, and reset the isolation scope level after joining the flusher thread.
  • Also fix test_schema_validator_rejects_string_timestamps which has the same pattern.

Fixes #108908

Test plan

  • Verified the previously failing pytest invocation now succeeds:
    pytest tests/sentry/spans/consumers/process/test_consumer.py::test_schema_validator_rejects_none_fields[span_id] tests/sentry/testutils/thread_leaks/test_pytest.py::TestSentryCapture::test_capture_event_allowlisted
    

The span consumer flusher thread sets `scope.level = "warning"` on the
sentry_sdk isolation scope. In tests, the flusher runs as a thread (not
a subprocess), so this modification leaks into subsequent tests and
overrides event levels set in the thread leak detection tests.

Wrap test body in try/finally to ensure flusher cleanup, and reset the
isolation scope level after joining the flusher thread.

Fixes #108908
@joshuarli
Copy link
Copy Markdown
Member Author

Superseded by #109105 which uses an autouse conftest fixture instead of per-test try/finally cleanup.

@joshuarli joshuarli closed this Feb 25, 2026
@joshuarli joshuarli deleted the fix/test-pollution-flusher-scope-leak-108908 branch February 25, 2026 22:40
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test pollution: tests/sentry/testutils/thread_leaks/test_pytest.py::TestSentryCapture::test_capture_event_allowlisted

1 participant