You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Django integration test suite uses @pytest.mark.forked (via pytest-forked) on 52 tests across 5 files to isolate global state. This dates back to #522 ("Less boxed testing") and was a pragmatic substitute for proper teardown.
Problem
pytest-forked is actively harmful in some scenarios:
Python 3.12 + asyncio + GitHub Actions: Forking a multi-threaded process and then running an asyncio loop in the child causes silent hangs (the loop inherits dead threads). This consumed the full 30-minute CI budget on the Django ASGI tests until test(django): Remove forking in ASGI tests #6410 dropped forked from those 10 tests.
Slow: Fork-per-test multiplies suite runtime.
Hides real isolation bugs: Tests pass under fork but would fail under proper sequential execution, masking integration setup that isn't idempotent.
Goal
Remove @pytest.mark.forked from every test under tests/integrations/django/ and replace it with explicit isolation.
Proposed approach
Extend (or autouse-wrap) the sentry_init fixture so the non-forked path also resets:
sentry_sdk.integrations._processed_integrations
sentry_sdk.integrations._installed_integrations
Add a reset_django_state fixture that snapshots and restores:
settings.MIDDLEWARE
Django signal receivers (request_started, request_finished, etc.)
Background
The Django integration test suite uses
@pytest.mark.forked(viapytest-forked) on 52 tests across 5 files to isolate global state. This dates back to #522 ("Less boxed testing") and was a pragmatic substitute for proper teardown.Problem
pytest-forkedis actively harmful in some scenarios:forkedfrom those 10 tests.Goal
Remove
@pytest.mark.forkedfrom every test undertests/integrations/django/and replace it with explicit isolation.Proposed approach
sentry_initfixture so the non-forked path also resets:sentry_sdk.integrations._processed_integrationssentry_sdk.integrations._installed_integrationsreset_django_statefixture that snapshots and restores:settings.MIDDLEWARErequest_started,request_finished, etc.)DjangoIntegration.setup_onceconnectsDjangoIntegration.setup_once(and submodule patches undersentry_sdk/integrations/django/) for non-idempotent module-level patching.Current state
Files still using
@pytest.mark.forkedundertests/integrations/django/(count viagrep -rc):test_basic.py(13)test_cache_module.py(14)test_db_query_data.py(10)test_db_transactions.py(12)test_data_scrubbing.py(3)The ASGI subset (
tests/integrations/django/asgi/test_asgi.py) was removed in #6410.