: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 AI agent tests (part 1) (#116226)
Paul D'Ambra47470fd588b4
diff --git a/ee/hogai/chat_agent/funnels/test/test_toolkit.py b/ee/hogai/chat_agent/funnels/test/test_toolkit.pyindex 5951323dc691..5a486b95cea8 100644--- a/ee/hogai/chat_agent/funnels/test/test_toolkit.py+++ b/ee/hogai/chat_agent/funnels/test/test_toolkit.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom ee.hogai.chat_agent.funnels.toolkit import generate_funnel_schema-class TestFunnelToolkit(BaseTest):+class TestFunnelToolkit(SimpleTestCase):def test_generate_funnel_schema_sorts_top_level_properties(self):schema = generate_funnel_schema()properties = schema["parameters"]["properties"]["query"]["properties"]diff --git a/ee/hogai/chat_agent/memory/test/test_parsers.py b/ee/hogai/chat_agent/memory/test/test_parsers.pyindex b4d48ac9b479..460fb605f401 100644--- a/ee/hogai/chat_agent/memory/test/test_parsers.py+++ b/ee/hogai/chat_agent/memory/test/test_parsers.py@@ -1,11 +1,11 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom langchain_core.messages import AIMessagefrom ee.hogai.chat_agent.memory.parsers import check_memory_collection_completed, compressed_memory_parser-class TestParsers(BaseTest):+class TestParsers(SimpleTestCase):def test_compressed_memory_parser(self):memory = "Hello\n\nWorld "self.assertEqual(compressed_memory_parser(memory), "Hello\nWorld ")diff --git a/ee/hogai/chat_agent/query_planner/test/test_toolkit.py b/ee/hogai/chat_agent/query_planner/test/test_toolkit.pyindex c6c12cbce708..9d4a81a33612 100644--- a/ee/hogai/chat_agent/query_planner/test/test_toolkit.py+++ b/ee/hogai/chat_agent/query_planner/test/test_toolkit.py@@ -2,9 +2,11 @@ from datetime import UTC, datetime, timedeltafrom textwrap import dedentimport time_machine-from posthog.test.base import APIBaseTest, BaseTest, ClickhouseTestMixin, _create_event, _create_person+from posthog.test.base import APIBaseTest, ClickhouseTestMixin, _create_event, _create_personfrom unittest.mock import MagicMock, patch+from django.test import SimpleTestCase+from parameterized import parameterizedfrom posthog.schema import (@@ -693,7 +695,7 @@ class TestTaxonomyAgentToolkit(ClickhouseTestMixin, APIBaseTest):self.assertIn("does not exist", result)-class TestFinalAnswerTool(BaseTest):+class TestFinalAnswerTool(SimpleTestCase):def test_normalize_plan(self):original = """Series:diff --git a/ee/hogai/chat_agent/retention/test/test_toolkit.py b/ee/hogai/chat_agent/retention/test/test_toolkit.pyindex 373f74bc7be6..91cb7f089ae3 100644--- a/ee/hogai/chat_agent/retention/test/test_toolkit.py+++ b/ee/hogai/chat_agent/retention/test/test_toolkit.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom ee.hogai.chat_agent.retention.toolkit import generate_retention_schema-class TestRetentionToolkit(BaseTest):+class TestRetentionToolkit(SimpleTestCase):def test_generate_retention_schema_sorts_top_level_properties(self):schema = generate_retention_schema()properties = schema["parameters"]["properties"]["query"]["properties"]diff --git a/ee/hogai/chat_agent/taxonomy/test/test_nodes.py b/ee/hogai/chat_agent/taxonomy/test/test_nodes.pyindex e83c3336ba6e..586d43c0b8dd 100644--- a/ee/hogai/chat_agent/taxonomy/test/test_nodes.py+++ b/ee/hogai/chat_agent/taxonomy/test/test_nodes.py@@ -1,6 +1,8 @@from posthog.test.base import BaseTestfrom unittest.mock import Mock, patch+from django.test import SimpleTestCase+from langchain_core.agents import AgentActionfrom langchain_core.runnables import RunnableConfigfrom parameterized import parameterized@@ -35,7 +37,7 @@ class ConcreteTaxonomyAgentToolsNode(TaxonomyAgentToolsNode[TaxonomyAgentState,pass-class TestPropertyTypesPrompt(BaseTest):+class TestPropertyTypesPrompt(SimpleTestCase):@parameterized.expand([("survey_dismissed", "$survey_dismissed/{survey_id}"),diff --git a/ee/hogai/chat_agent/taxonomy/test/test_tools.py b/ee/hogai/chat_agent/taxonomy/test/test_tools.pyindex 306bd20b1b46..1ec69ac8568f 100644--- a/ee/hogai/chat_agent/taxonomy/test/test_tools.py+++ b/ee/hogai/chat_agent/taxonomy/test/test_tools.py@@ -1,11 +1,11 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom pydantic import BaseModelfrom ee.hogai.chat_agent.taxonomy.tools import base_final_answer, get_dynamic_entity_tools-class TestDynamicEntityTools(BaseTest):+class TestDynamicEntityTools(SimpleTestCase):def test_get_dynamic_entity_tools_basic(self):team_group_types: list[str] = ["organization", "project"]@@ -68,7 +68,7 @@ class TestDynamicEntityTools(BaseTest):self.assertIn("property_name", values_fields)-class TestFinalAnswerModel(BaseTest):+class TestFinalAnswerModel(SimpleTestCase):class TestAnswerModel(BaseModel):value: strdiff --git a/ee/hogai/chat_agent/trends/test/test_toolkit.py b/ee/hogai/chat_agent/trends/test/test_toolkit.pyindex 0d18ef5ca8a8..e57244057cd3 100644--- a/ee/hogai/chat_agent/trends/test/test_toolkit.py+++ b/ee/hogai/chat_agent/trends/test/test_toolkit.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom ee.hogai.chat_agent.trends.toolkit import generate_trends_schema-class TestTrendsToolkit(BaseTest):+class TestTrendsToolkit(SimpleTestCase):def test_generate_trends_schema_sorts_top_level_properties(self):schema = generate_trends_schema()properties = schema["parameters"]["properties"]["query"]["properties"]diff --git a/ee/hogai/context/insight/format/test/test_lifecycle.py b/ee/hogai/context/insight/format/test/test_lifecycle.pyindex 038f613701b8..b815d8f54f97 100644--- a/ee/hogai/context/insight/format/test/test_lifecycle.py+++ b/ee/hogai/context/insight/format/test/test_lifecycle.py@@ -1,4 +1,4 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import AssistantLifecycleEventsNode, AssistantLifecycleQuery, EventsNode, LifecycleQuery@@ -24,7 +24,7 @@ def _make_result(event_id, event_name, status, data, days, order=0, custom_name=}-class TestLifecycleResultsFormatter(BaseTest):+class TestLifecycleResultsFormatter(SimpleTestCase):def test_format_single_series(self):results = [_make_result("$pageview", "$pageview", "new", [100, 80, 60], ["2025-01-01", "2025-01-02", "2025-01-03"]),diff --git a/ee/hogai/context/insight/format/test/test_paths.py b/ee/hogai/context/insight/format/test/test_paths.pyindex d03265b1297b..c53cf73c8d59 100644--- a/ee/hogai/context/insight/format/test/test_paths.py+++ b/ee/hogai/context/insight/format/test/test_paths.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom .. import PathsResultsFormatter-class TestPathsResultsFormatter(BaseTest):+class TestPathsResultsFormatter(SimpleTestCase):def test_format_paths(self):results = [{"source": "1_/home", "target": "2_/pricing", "value": 150, "average_conversion_time": 150.0},diff --git a/ee/hogai/context/insight/format/test/test_retention.py b/ee/hogai/context/insight/format/test/test_retention.pyindex d67ad799172b..f82c44196363 100644--- a/ee/hogai/context/insight/format/test/test_retention.py+++ b/ee/hogai/context/insight/format/test/test_retention.py@@ -1,11 +1,11 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import AssistantRetentionEventsNode, AssistantRetentionFilter, AssistantRetentionQueryfrom .. import RetentionResultsFormatter-class TestRetentionResultsFormatter(BaseTest):+class TestRetentionResultsFormatter(SimpleTestCase):def test_format_retention(self):results = [{diff --git a/ee/hogai/context/insight/format/test/test_stickiness.py b/ee/hogai/context/insight/format/test/test_stickiness.pyindex 5771b20d6ab1..ad1bfe110c49 100644--- a/ee/hogai/context/insight/format/test/test_stickiness.py+++ b/ee/hogai/context/insight/format/test/test_stickiness.py@@ -1,11 +1,11 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import AssistantStickinessQueryfrom .. import StickinessResultsFormatter-class TestStickinessResultsFormatter(BaseTest):+class TestStickinessResultsFormatter(SimpleTestCase):def test_stickiness_single_series(self):results = [{diff --git a/ee/hogai/context/insight/format/test/test_utils.py b/ee/hogai/context/insight/format/test/test_utils.pyindex 05e93e0ca1fd..e14e6ec50008 100644--- a/ee/hogai/context/insight/format/test/test_utils.py+++ b/ee/hogai/context/insight/format/test/test_utils.py@@ -1,6 +1,6 @@from datetime import date-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom ..utils import (format_date,@@ -12,7 +12,7 @@ from ..utils import ()-class TestFormatUtils(BaseTest):+class TestFormatUtils(SimpleTestCase):def test_format_number(self):self.assertEqual(format_number(1), "1")self.assertEqual(format_number(1.0), "1")diff --git a/ee/hogai/context/insight/test/test_query_executor.py b/ee/hogai/context/insight/test/test_query_executor.pyindex 6c520e9d65d7..e5aa915b2c87 100644--- a/ee/hogai/context/insight/test/test_query_executor.py+++ b/ee/hogai/context/insight/test/test_query_executor.py@@ -990,7 +990,7 @@ class TestExecuteAndFormatQuery(NonAtomicBaseTest):self.assertIn("1_/home|2_/pricing|150|2m 30s", result)-class TestValidateAssistantQuery(NonAtomicBaseTest):+class TestValidateAssistantQuery(SimpleTestCase):"""Tests for the validate_assistant_query function"""CLASS_DATA_LEVEL_SETUP = Falsediff --git a/ee/hogai/core/plan_mode/test/test_executables.py b/ee/hogai/core/plan_mode/test/test_executables.pyindex dd702480169d..06eb3e55e4ef 100644--- a/ee/hogai/core/plan_mode/test/test_executables.py+++ b/ee/hogai/core/plan_mode/test/test_executables.py@@ -2,6 +2,8 @@ import pytestfrom posthog.test.base import BaseTestfrom unittest.mock import AsyncMock, patch+from django.test import SimpleTestCase+from langchain_core.messages import BaseMessagefrom langchain_core.runnables import RunnableConfigfrom parameterized import parameterized@@ -27,7 +29,7 @@ class DummyChatAgentPromptBuilder(AgentPromptBuilder):return [BaseMessage(content="Dummy prompt")]-class TestSupermodeReducer(BaseTest):+class TestSupermodeReducer(SimpleTestCase):"""Test the supermode reducer behavior."""def test_replace_if_not_none_ignores_none_values(self):diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex d0abf6dcd5a5..5d1720dd4496 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -15,21 +15,6 @@ ee/billing/test/test_usage_signals.py::TestUsageSignalsDataClassee/clickhouse/materialized_columns/test/test_analyze.py::TestMaterializedColumnsAnalyzeee/clickhouse/models/test/test_dead_letter_queue.py::TestDeadLetterQueueee/clickhouse/models/test/test_property.py::TestPropDenormalized-ee/hogai/chat_agent/funnels/test/test_toolkit.py::TestFunnelToolkit-ee/hogai/chat_agent/memory/test/test_parsers.py::TestParsers-ee/hogai/chat_agent/query_planner/test/test_toolkit.py::TestFinalAnswerTool-ee/hogai/chat_agent/retention/test/test_toolkit.py::TestRetentionToolkit-ee/hogai/chat_agent/taxonomy/test/test_nodes.py::TestPropertyTypesPrompt-ee/hogai/chat_agent/taxonomy/test/test_tools.py::TestDynamicEntityTools-ee/hogai/chat_agent/taxonomy/test/test_tools.py::TestFinalAnswerModel-ee/hogai/chat_agent/trends/test/test_toolkit.py::TestTrendsToolkit-ee/hogai/context/insight/format/test/test_lifecycle.py::TestLifecycleResultsFormatter-ee/hogai/context/insight/format/test/test_paths.py::TestPathsResultsFormatter-ee/hogai/context/insight/format/test/test_retention.py::TestRetentionResultsFormatter-ee/hogai/context/insight/format/test/test_stickiness.py::TestStickinessResultsFormatter-ee/hogai/context/insight/format/test/test_utils.py::TestFormatUtils-ee/hogai/context/insight/test/test_query_executor.py::TestValidateAssistantQuery-ee/hogai/core/plan_mode/test/test_executables.py::TestSupermodeReduceree/hogai/utils/test/test_dispatcher.py::TestDispatcherIntegrationee/hogai/utils/test/test_openai.py::TestOpenAIUtilsee/partners/stripe/api/provisioning/test/test_services_catalog.py::TestServicesCatalog@@ -50,7 +35,6 @@ posthog/api/test/test_toolbar_oauth_endpoint_auth.py::TestToolbarOAuthScopesConfposthog/api/test/test_toolbar_oauth_primitives.py::TestTokenEndpointStatusRemappingposthog/api/test/test_toolbar_oauth_primitives.py::TestToolbarOAuthStateCacheposthog/caching/test/test_redis_cluster_keys.py::TestRedisClusterKeySlots-products/cdp/backend/templates/avo/test_template_avo.py::TestTemplateMigrationposthog/clickhouse/client/test/test_limit.py::TestRateLimitposthog/clickhouse/test/test_deletion_coverage.py::TestDeletionCoverageposthog/helpers/test_markdown_safety.py::TestStripExternalLinks@@ -139,6 +123,7 @@ products/business_knowledge/backend/tests/test_logic.py::TestChunkerproducts/business_knowledge/backend/tests/test_url_ingest.py::TestFetchUrlproducts/business_knowledge/backend/tests/test_url_ingest.py::TestNormalizeUrlproducts/business_knowledge/backend/tests/test_url_ingest.py::TestParseHtml+products/cdp/backend/templates/avo/test_template_avo.py::TestTemplateMigrationproducts/conversations/backend/api/tests/test_teams_token_storage.py::TestTrustedTeamsServiceUrlproducts/data_modeling/backend/test/test_saved_query_dag_sync.py::TestGetDagIdproducts/experiments/backend/hogql_queries/test/test_stats_config.py::TestSequentialStatsConfig