fix(tests): Use override_settings instead of direct settings mutation#109414
Merged
fix(tests): Use override_settings instead of direct settings mutation#109414
Conversation
Direct `settings.SENTRY_METRICS_INDEXER_DEBUG_LOG_SAMPLE_RATE = 1.0` mutations leak state to subsequent tests. Use `@override_settings` to ensure automatic cleanup after each test.
…browser SDK tests [skip ci] Expand scope to cover all direct `settings.X = value` mutations across the test suite. The JS SDK loader tests had ~15 direct mutations in test methods plus an autouse fixture that set settings without cleanup. - test_js_sdk_loader.py: Replace autouse fixture with @override_settings on class; replace all per-method settings mutations with @override_settings - test_create_organization.py: Wrap PRIVACY_URL/TERMS_URL in @override_settings - test_quick_start.py: Same - test_browsersdkversion.py: Wrap JS_SDK_LOADER_SDK_VERSION in @override_settings
rbro112
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
settings.X = valuemutations with@override_settingsacross the test suiteFiles fixed
tests/sentry/sentry_metrics/test_batch.py(8 occurrences) —SENTRY_METRICS_INDEXER_DEBUG_LOG_SAMPLE_RATEtests/sentry/sentry_metrics/test_gen_metrics_multiprocess_steps.py(1) — sametests/sentry/sentry_metrics/test_rh_metrics_multiprocess_steps.py(1) — sametests/sentry/web/frontend/test_js_sdk_loader.py(~15 occurrences) —JS_SDK_LOADER_DEFAULT_SDK_URL,JS_SDK_LOADER_SDK_VERSION; also replaced broken autouse fixture with@override_settingson the classtests/acceptance/test_create_organization.py(2) —PRIVACY_URL,TERMS_URLtests/acceptance/test_quick_start.py(2) —PRIVACY_URL,TERMS_URLtests/sentry/loader/test_browsersdkversion.py(1) —JS_SDK_LOADER_SDK_VERSIONWhy
Per PYTEST-GUIDELINES.md §4a: "Mutates settings globally, leaks to subsequent tests." Direct
settings.X = valueassignment bypasses Django's settings restoration mechanism, causing test pollution when test execution order changes.