: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
chore(tests): avoid database setup in product backend tests (part 6) (#116236)
Paul D'Ambra0b49653a82c9
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex 8ad02c0f7e67..607f46dd6651 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -132,29 +132,7 @@ products/revenue_analytics/backend/test/test_joins.py::TestGetCustomerRevenueVieproducts/streamlit_apps/backend/tests/test_tasks.py::TestAutoRestartCrashedStreamlitSandboxesproducts/streamlit_apps/backend/tests/test_tasks.py::TestStopIdleStreamlitSandboxesproducts/surveys/backend/api/test/test_external_surveys.py::TestExternalSurveysURLs-products/tasks/backend/tests/test_api.py::TestTaskRunRedisStreamKeepaliveproducts/tasks/backend/tests/test_api.py::TestUsageLimitResponse-products/tasks/backend/tests/test_facade.py::TestAppendLogAgentActivity-products/tasks/backend/tests/test_facade.py::TestFacadeImports-products/tasks/backend/tests/test_repository_readiness.py::TestApplicableCapabilities-products/tasks/backend/tests/test_repository_readiness.py::TestCandidatePathScore-products/tasks/backend/tests/test_repository_readiness.py::TestClassifyRepository-products/tasks/backend/tests/test_repository_readiness.py::TestSelectCandidatePaths-products/tasks/backend/tests/test_repository_readiness.py::TestShouldScanPath-products/tasks/backend/tests/test_webhooks.py::TestAccountType-products/warehouse_sources/backend/tests/api/test_external_data_source.py::TestGetOAuthIntegrationKinds-products/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.py::TestPatternsCompile-products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py::TestComputeFiltersEligibilityHash-products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py::TestComputeShapeCapKey-products/web_analytics/backend/test/test_max_tools.py::TestWebAnalyticsAssistantFilters-products/web_analytics/backend/test/test_path_cleaning_suggestions.py::TestExtractJson-products/web_analytics/backend/test/test_path_cleaning_suggestions.py::TestValidateAndAnnotateRules-products/web_analytics/dags/tests/test_cache_warming.py::TestCanonicalizeLazyReplay-products/web_analytics/dags/tests/test_cache_warming.py::TestDeepenToWidestWarmableRangeproducts/web_analytics/dags/tests/test_cache_warming.py::TestFleetQuerySelection-products/web_analytics/dags/tests/test_cache_warming.py::TestMaybeExpandWarmingDateRange-products/web_analytics/dags/tests/test_cache_warming.py::TestMaybeOptIntoLazyPrecomputeproducts/web_analytics/dags/tests/test_cache_warming.py::TestSplitWarmableQueriesproducts/web_analytics/dags/tests/test_cache_warming.py::TestWarmableQueriesCaching-products/workflows/backend/test/test_backfill_workflows_slack_integration.py::TestRewriteSlackWorkspaceInActions-products/workflows/backend/test/test_email_sending_tier.py::TestEmailSendingTierDecisiondiff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex ef25b93691c9..db6e77f0e2df 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -12249,7 +12249,7 @@ class TestTaskRunStreamAPI(BaseTaskAPITest):self.assertTrue(asyncio.run(_watched()))-class TestTaskRunRedisStreamKeepalive(TestCase):+class TestTaskRunRedisStreamKeepalive(SimpleTestCase):def test_read_stream_entries_yields_keepalive_sentinel_when_idle(self):class StubRedis:def __init__(self):diff --git a/products/tasks/backend/tests/test_facade.py b/products/tasks/backend/tests/test_facade.pyindex c15d42cccb93..01aec9d143fe 100644--- a/products/tasks/backend/tests/test_facade.py+++ b/products/tasks/backend/tests/test_facade.py@@ -8,7 +8,7 @@ from unittest.mock import MagicMock, patchfrom django.apps import appsfrom django.db import close_old_connections-from django.test import TestCase, TransactionTestCase+from django.test import SimpleTestCase, TestCase, TransactionTestCasefrom django.utils import timezone as django_timezonefrom parameterized import parameterized@@ -51,7 +51,7 @@ FACADE_MODULES = []-class TestFacadeImports(TestCase):+class TestFacadeImports(SimpleTestCase):@parameterized.expand([(m,) for m in FACADE_MODULES])def test_module_imports_and_all_symbols_resolve(self, module_path):module = importlib.import_module(module_path)@@ -1886,7 +1886,7 @@ class TestFacadeReadsAndMappers(TestCase):self.assertEqual(run.state.get("ai_stage"), "wizard_pr_agent")-class TestAppendLogAgentActivity(TestCase):+class TestAppendLogAgentActivity(SimpleTestCase):# Guards the self-sustaining heartbeat loop: infra log lines (credential refresh -># _posthog/console) heartbeating with agent_active=True reset the workflow's inactivity# timer on every write, so a run whose agent went silent could never time out.diff --git a/products/tasks/backend/tests/test_repository_readiness.py b/products/tasks/backend/tests/test_repository_readiness.pyindex 9a890c0a9ebb..2e6197483ccf 100644--- a/products/tasks/backend/tests/test_repository_readiness.py+++ b/products/tasks/backend/tests/test_repository_readiness.py@@ -3,7 +3,7 @@ from typing import Anyfrom unittest.mock import MagicMock, patchfrom django.core.cache import cache-from django.test import TestCase, override_settings+from django.test import SimpleTestCase, TestCase, override_settingsfrom parameterized import parameterized@@ -34,7 +34,7 @@ def _empty_evidence(**overrides: Any) -> RepositoryScanEvidence:)-class TestShouldScanPath(TestCase):+class TestShouldScanPath(SimpleTestCase):@parameterized.expand([("typescript", "src/index.ts", True),@@ -65,7 +65,7 @@ class TestShouldScanPath(TestCase):assert _should_scan_path(path) == expected-class TestCandidatePathScore(TestCase):+class TestCandidatePathScore(SimpleTestCase):@parameterized.expand([("no_keywords", "src/utils.ts", 1),@@ -87,7 +87,7 @@ class TestCandidatePathScore(TestCase):assert _candidate_path_score(path) == expected-class TestSelectCandidatePaths(TestCase):+class TestSelectCandidatePaths(SimpleTestCase):def test_filters_unscannable(self) -> None:paths = ["src/main.ts", "README.md", "package.json", "src/utils.py"]result = _select_candidate_paths(paths)@@ -104,7 +104,7 @@ class TestSelectCandidatePaths(TestCase):assert len(result) == MAX_CANDIDATE_PATHS-class TestClassifyRepository(TestCase):+class TestClassifyRepository(SimpleTestCase):@parameterized.expand([("test_repo", "org/test-app", [], _empty_evidence(), "test_or_sandbox", True),@@ -169,7 +169,7 @@ class TestClassifyRepository(TestCase):assert excluded is True-class TestApplicableCapabilities(TestCase):+class TestApplicableCapabilities(SimpleTestCase):@parameterized.expand([("excluded", "frontend_js", True, {"tracking": False, "computer_vision": False, "errors": False}),diff --git a/products/tasks/backend/tests/test_webhooks.py b/products/tasks/backend/tests/test_webhooks.pyindex 330e57c665dc..7b17fb423fcb 100644--- a/products/tasks/backend/tests/test_webhooks.py+++ b/products/tasks/backend/tests/test_webhooks.py@@ -7,7 +7,7 @@ from unittest.mock import MagicMock, patchfrom django.core.cache import cachefrom django.db import OperationalError-from django.test import TestCase+from django.test import SimpleTestCase, TestCasefrom parameterized import parameterizedfrom prometheus_client import REGISTRY@@ -35,7 +35,7 @@ from products.tasks.backend.models import Loop, Task, TaskRun, TaskThreadMessagefrom products.tasks.backend.webhooks import _task_run_scope_team_ids, find_task_run-class TestAccountType(TestCase):+class TestAccountType(SimpleTestCase):@parameterized.expand([("org_owner", {"repository": {"owner": {"type": "Organization"}}}, "organization"),diff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.pyindex 9ea6e20eb2c9..7418dfa98b95 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py@@ -13477,7 +13477,7 @@ class TestExternalDataSourceStoreCredentials(APIBaseTest):assert [result["credential_id"] for result in response.json()] == [str(newer.pk), str(older.pk)]-class TestGetOAuthIntegrationKinds(APIBaseTest):+class TestGetOAuthIntegrationKinds(SimpleTestCase):"""These kinds are what the OAuth accounts endpoint pins a caller-supplied integration id against, soa source whose OAuth field this fails to find would have its account listing rejected."""diff --git a/products/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.py b/products/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.pyindex 46003234ad55..499cb479f5d1 100644--- a/products/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.py+++ b/products/web_analytics/backend/hogql_queries/test/test_custom_bot_definitions.py@@ -1,5 +1,7 @@import pytest-from posthog.test.base import BaseTest, ClickhouseTestMixin+from posthog.test.base import ClickhouseTestMixin++from django.test import SimpleTestCasefrom parameterized import parameterized@@ -475,7 +477,8 @@ class TestCompositeBranch:assert (branch is not None) == expected_branch-class TestPatternsCompile(ClickhouseTestMixin, BaseTest):[email protected]("clickhouse_database")+class TestPatternsCompile(ClickhouseTestMixin, SimpleTestCase):@parameterized.expand([# Python's re accepts a huge bounded repeat and a POSIX class it does not know; ClickHousediff --git a/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py b/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.pyindex 30cca5eb6c9a..38bfa55b7fc5 100644--- a/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py+++ b/products/web_analytics/backend/hogql_queries/test/test_web_lazy_precompute_common.py@@ -6,7 +6,7 @@ import time_machinefrom posthog.test.base import APIBaseTest, BaseTest, ClickhouseTestMixinfrom unittest import mock-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.utils import timezone as django_timezonefrom parameterized import parameterized@@ -454,7 +454,7 @@ def _stats()-class TestComputeFiltersEligibilityHash(BaseTest):+class TestComputeFiltersEligibilityHash(SimpleTestCase):def test_stable_across_calls_with_identical_query(self) -> None:q = _overview()assert compute_filters_eligibility_hash(q, "UTC") == compute_filters_eligibility_hash(q, "UTC")@@ -533,7 +533,7 @@ class TestComputeFiltersEligibilityHash(BaseTest):int(h, 16)-class TestComputeShapeCapKey(BaseTest):+class TestComputeShapeCapKey(SimpleTestCase):def test_date_range_variants_share_one_slot(self) -> None:# Buckets are reused across requested ranges (the namespace sentinelizes time# windows), so date-range variants of one shape must map to one cap key —diff --git a/products/web_analytics/backend/test/test_max_tools.py b/products/web_analytics/backend/test/test_max_tools.pyindex 7f423a727271..453c440463ec 100644--- a/products/web_analytics/backend/test/test_max_tools.py+++ b/products/web_analytics/backend/test/test_max_tools.py@@ -6,6 +6,8 @@ from posthog.test.base import (flush_persons_and_events,)+from django.test import SimpleTestCase+from posthog.schema import (CompareFilter,EventPropertyFilter,@@ -58,7 +60,7 @@ class TestWebAnalyticsPropertyValues(ClickhouseDestroyTablesMixin, APIBaseTest):assert set(values) == {"US", "UK"}-class TestWebAnalyticsAssistantFilters(APIBaseTest):+class TestWebAnalyticsAssistantFilters(SimpleTestCase):def test_filters_validation(self):filters = WebAnalyticsAssistantFilters(date_from="-7d",diff --git a/products/web_analytics/backend/test/test_path_cleaning_suggestions.py b/products/web_analytics/backend/test/test_path_cleaning_suggestions.pyindex f2e1179839ac..e1185ef37617 100644--- a/products/web_analytics/backend/test/test_path_cleaning_suggestions.py+++ b/products/web_analytics/backend/test/test_path_cleaning_suggestions.py@@ -1,6 +1,8 @@from posthog.test.base import BaseTestfrom unittest.mock import patch+from django.test import SimpleTestCase+from parameterized import parameterizedfrom products.web_analytics.backend.path_cleaning_suggestions import service@@ -21,7 +23,7 @@ SAMPLE_PATHS = []-class TestValidateAndAnnotateRules(BaseTest):+class TestValidateAndAnnotateRules(SimpleTestCase):def test_keeps_valid_rule_with_dense_order_and_annotations(self) -> None:rules = [SuggestedRule(regex=r"/users/\d+/profile", alias="/users/<id>/profile", reason="user id")]annotated = validate_and_annotate_rules(rules, SAMPLE_PATHS)@@ -56,7 +58,7 @@ class TestValidateAndAnnotateRules(BaseTest):self.assertEqual(annotated[0].order, 0)-class TestExtractJson(BaseTest):+class TestExtractJson(SimpleTestCase):@parameterized.expand([("plain", '{"rules": []}'),diff --git a/products/web_analytics/dags/tests/test_cache_warming.py b/products/web_analytics/dags/tests/test_cache_warming.pyindex 18c81f991c49..616ce2fbe2dd 100644--- a/products/web_analytics/dags/tests/test_cache_warming.py+++ b/products/web_analytics/dags/tests/test_cache_warming.py@@ -8,6 +8,7 @@ from types import SimpleNamespacefrom posthog.test.base import BaseTestfrom unittest.mock import MagicMock, call, patch+from django.test import SimpleTestCasefrom django.utils.dateparse import parse_datetimeimport dagster@@ -43,7 +44,7 @@ from products.web_analytics.dags.cache_warming import ()-class TestMaybeOptIntoLazyPrecompute(BaseTest):+class TestMaybeOptIntoLazyPrecompute(SimpleTestCase):def test_web_query_gets_opt_in(self) -> None:# If this breaks, the warmer silently stops building precompute buckets# for replayed shapes wherever the opt-in default still applies.@@ -66,7 +67,7 @@ class TestMaybeOptIntoLazyPrecompute(BaseTest):self.assertEqual(maybe_opt_into_lazy_precompute(query), query)-class TestMaybeExpandWarmingDateRange(BaseTest):+class TestMaybeExpandWarmingDateRange(SimpleTestCase):@parameterized.expand([# Sub-30d ranges deepen to -30d; if these stop expanding, warming@@ -123,7 +124,7 @@ class TestMaybeExpandWarmingDateRange(BaseTest):self.assertEqual(maybe_expand_warming_date_range(query), query)-class TestDeepenToWidestWarmableRange(BaseTest):+class TestDeepenToWidestWarmableRange(SimpleTestCase):@parameterized.expand([# Deepen to the widest exact range the shape's demand covers, so one@@ -334,7 +335,7 @@ class TestBuildReplayRunner(BaseTest):self.assertEqual(base_runner.get_cache_key(), variant_runner.get_cache_key())-class TestCanonicalizeLazyReplay(BaseTest):+class TestCanonicalizeLazyReplay(SimpleTestCase):@parameterized.expand([("steps_up_to_next_multiple", "-31d", "-45d"),diff --git a/products/workflows/backend/test/test_backfill_workflows_slack_integration.py b/products/workflows/backend/test/test_backfill_workflows_slack_integration.pyindex a2902f06f4f2..2a78d70a9fb0 100644--- a/products/workflows/backend/test/test_backfill_workflows_slack_integration.py+++ b/products/workflows/backend/test/test_backfill_workflows_slack_integration.py@@ -2,6 +2,7 @@ from posthog.test.base import BaseTestfrom unittest.mock import patchfrom django.core.management import call_command+from django.test import SimpleTestCasefrom posthog.models import Team@@ -29,7 +30,7 @@ def _slack_action(action_id: str, slack_workspace_value: int | None) -> dict:}-class TestRewriteSlackWorkspaceInActions(BaseTest):+class TestRewriteSlackWorkspaceInActions(SimpleTestCase):def test_rewrites_matching_value(self):actions = [_slack_action("a1", backfill.OLD_INTEGRATION_ID)]new_actions, changed = _rewrite_slack_workspace_in_actions(actions)diff --git a/products/workflows/backend/test/test_email_sending_tier.py b/products/workflows/backend/test/test_email_sending_tier.pyindex 8cddd7634a7b..6509c8d0b0d4 100644--- a/products/workflows/backend/test/test_email_sending_tier.py+++ b/products/workflows/backend/test/test_email_sending_tier.py@@ -3,7 +3,7 @@ from datetime import timedeltafrom posthog.test.base import BaseTestfrom unittest.mock import patch-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.utils import timezonefrom parameterized import parameterized@@ -74,7 +74,7 @@ def clean_days(count: int, sent_per_day: int, *, days_ago: int = 0) -> dict[str,@override_settings(**TIER_SETTINGS)-class TestEmailSendingTierDecision(BaseTest):+class TestEmailSendingTierDecision(SimpleTestCase):@parameterized.expand([(tier, caps) for tier, caps in enumerate(zip(TIER_HOURLY_CAPS, TIER_DAILY_CAPS))])def test_tier_maps_to_its_caps(self, tier: int, caps: tuple[int, int]) -> None:limits = get_email_sending_tier_limits(tier)