:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ci): cut per-process pytest boot cost (langsmith disable, faker disable, earlier GC window) (#69941)
Paul D'Ambra92214483c4ab
diff --git a/conftest.py b/conftest.pyindex 9b3ab84b1117..4bf8b74dd8c9 100644--- a/conftest.py+++ b/conftest.py@@ -8,8 +8,10 @@ import pytest# phase only adds pauses (seconds on a full-tree CI shard collection). Run the boot# with GC off, then freeze the survivors into the permanent generation so the# collector never rescans them during the test phase. Tests themselves run with GC-# enabled as usual. (django.setup() runs in pytest-django's load_initial_conftests,-# before conftest files load, so it stays outside the window.)+# enabled as usual. The window normally opens even earlier, in the pytest_boot_gc+# plugin (`-p pytest_boot_gc` in pytest.ini), so that django.setup() (which+# pytest-django runs before conftest files load) sits inside it too; the disable+# here is the fallback for runs that don't load that plugin (e.g. ee/pytest.ini).gc.disable()diff --git a/pytest.ini b/pytest.iniindex b521fcdc6451..9910004ec9c1 100644--- a/pytest.ini+++ b/pytest.ini@@ -7,9 +7,15 @@ DJANGO_SETTINGS_MODULE = posthog.settings# --pytest-durations=0 disables the pytest-durations plugin by default; CI shard steps re-enable it explicitly# -p no:tach disables tach's pytest plugin: without --tach it builds the full import graph (~5-10s# per invocation) only to print a "could be skipped" hint. Opt back in with: pytest -p tach --tach-# -p no:langsmith skips the langsmith pytest plugin (auto-registered by a transitive dependency,-# ~0.8s of imports per invocation); nothing in this repo uses langsmith's pytest integration-addopts = -p no:warnings -p no:tach -p no:langsmith --reuse-db --pytest-durations=0 --ignore=posthog/user_scripts --ignore=services/llm-gateway --ignore=services/stripe-mock --ignore=common/ingestion/acceptance_tests --ignore=tools/hogli --ignore=tools/hogli-commands --ignore=tools/traffic-sim --ignore=tools/query-performance-ai+# -p no:langsmith_plugin skips the langsmith pytest plugin (auto-registered by a transitive dependency,+# ~0.8s of imports per invocation); nothing in this repo uses langsmith's pytest integration.+# Note: the pytest11 entry point name is "langsmith_plugin" (module langsmith.pytest_plugin), not+# "langsmith", so `-p no:langsmith` silently fails to match anything and the plugin still loads.+# -p no:faker skips faker's auto-registered pytest plugin (~75ms of imports per invocation);+# nothing in this repo uses the `faker` fixture or the library (faker is a transitive dep)+# -p pytest_boot_gc opens the boot GC window (gc.disable) before pytest-django runs+# django.setup(), which happens before conftest files load; the root conftest closes it+addopts = -p no:warnings -p no:tach -p no:langsmith_plugin -p no:faker -p pytest_boot_gc --reuse-db --pytest-durations=0 --ignore=posthog/user_scripts --ignore=services/llm-gateway --ignore=services/stripe-mock --ignore=common/ingestion/acceptance_tests --ignore=tools/hogli --ignore=tools/hogli-commands --ignore=tools/traffic-sim --ignore=tools/query-performance-aimarkers =eediff --git a/pytest_boot_gc.py b/pytest_boot_gc.pynew file mode 100644index 000000000000..1b20c3630f7a--- /dev/null+++ b/pytest_boot_gc.py@@ -0,0 +1,15 @@+"""Early-loaded pytest plugin (see `-p pytest_boot_gc` in pytest.ini) that opens the+boot GC window before django.setup() runs.++The boot window itself (freeze + re-enable + thresholds) lives in the root+conftest.py (`_end_gc_boot_window`). But conftest files load *after*+pytest-django's load_initial_conftests has run django.setup(), so the several+million permanent allocations of settings + app population still paid automatic+GC pauses (~0.2s per process). `-p` plugins load before initial conftests, which+puts django.setup() inside the window too. Everything here must stay import-light:+this module runs before any of the test session's real setup.+"""++import gc++gc.disable()