: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 2) (#116227)
Paul D'Ambra6b95b33e0869
diff --git a/ee/hogai/core/test/test_artifacts.py b/ee/hogai/core/test/test_artifacts.pyindex b67ba271566d..898951f0e430 100644--- a/ee/hogai/core/test/test_artifacts.py+++ b/ee/hogai/core/test/test_artifacts.py@@ -1,5 +1,6 @@import pytest-from posthog.test.base import BaseTest++from django.test import SimpleTestCasefrom parameterized import parameterizedfrom pydantic import ValidationError@@ -20,7 +21,7 @@ from posthog.schema import ()-class TestDocumentBlocks(BaseTest):+class TestDocumentBlocks(SimpleTestCase):@parameterized.expand([("simple_markdown", "# Hello World", "# Hello World"),@@ -75,7 +76,7 @@ class TestDocumentBlocks(BaseTest):self.assertEqual(block.timestamp_ms, 0)-class TestDocumentArtifactContent(BaseTest):+class TestDocumentArtifactContent(SimpleTestCase):def test_empty_blocks(self):content = DocumentArtifactContent(blocks=[])self.assertEqual(content.blocks, [])@@ -127,7 +128,7 @@ class TestDocumentArtifactContent(BaseTest):self.assertEqual(block2.session_id, "sess")-class TestVisualizationArtifactContent(BaseTest):+class TestVisualizationArtifactContent(SimpleTestCase):def test_trends_query(self):trends = AssistantTrendsQuery(series=[])content = VisualizationArtifactContent(query=trends, name="Test Trends", description="Shows trend data")diff --git a/ee/hogai/core/test/test_base_callback_handlers.py b/ee/hogai/core/test/test_base_callback_handlers.pyindex d6e185ab8dc5..7f0810337e6c 100644--- a/ee/hogai/core/test/test_base_callback_handlers.py+++ b/ee/hogai/core/test/test_base_callback_handlers.py@@ -340,7 +340,7 @@ class TestBaseAgentRunnerCallbackHandlers(BaseTest):self.assertIsInstance(runner._callback_handlers[0], MaxCallbackHandler)-class TestSubagentCallbackHandler(BaseTest):+class TestSubagentCallbackHandler(SimpleTestCase):def setUp(self):super().setUp()self.mock_client = Mock()diff --git a/ee/hogai/core/test/test_dispatcher_integration.py b/ee/hogai/core/test/test_dispatcher_integration.pyindex c1212618140c..5074865fd3dd 100644--- a/ee/hogai/core/test/test_dispatcher_integration.py+++ b/ee/hogai/core/test/test_dispatcher_integration.py@@ -6,9 +6,10 @@ These tests ensure that the dispatcher pattern works correctly end-to-end in reafrom typing import cast-from posthog.test.base import BaseTestfrom unittest.mock import MagicMock, patch+from django.test import SimpleTestCase+from langchain_core.runnables import RunnableConfigfrom posthog.schema import AssistantMessage@@ -47,7 +48,7 @@ class MockAssistantNode(BaseAssistantNode[AssistantState, PartialAssistantState]return PartialAssistantState(messages=[AssistantMessage(content="Final result")])-class TestDispatcherIntegration(BaseTest):+class TestDispatcherIntegration(SimpleTestCase):"""Test dispatcher integration with BaseAssistantNode."""def setUp(self):diff --git a/ee/hogai/research_agent/test/test_runner.py b/ee/hogai/research_agent/test/test_runner.pyindex a80ac41e0f8a..344c1af3fc62 100644--- a/ee/hogai/research_agent/test/test_runner.py+++ b/ee/hogai/research_agent/test/test_runner.py@@ -3,6 +3,8 @@ from uuid import uuid4from posthog.test.base import BaseTest, ClickhouseTestMixinfrom unittest.mock import AsyncMock, patch+from django.test import SimpleTestCase+from posthog.schema import AgentMode, AssistantMessage, HumanMessagefrom products.posthog_ai.backend.models.assistant import Conversation@@ -12,7 +14,7 @@ from ee.hogai.utils.types import AssistantState, PartialAssistantStatefrom ee.hogai.utils.types.base import AssistantNodeName-class TestResearchAgentRunnerConfiguration(BaseTest):+class TestResearchAgentRunnerConfiguration(SimpleTestCase):def test_streaming_nodes_includes_root(self):self.assertIn(AssistantNodeName.ROOT, STREAMING_NODES)diff --git a/ee/hogai/summarizers/test/test_property_filters.py b/ee/hogai/summarizers/test/test_property_filters.pyindex 2faaddac9ee3..63ae8504123b 100644--- a/ee/hogai/summarizers/test/test_property_filters.py+++ b/ee/hogai/summarizers/test/test_property_filters.py@@ -1,4 +1,4 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import (DataWarehousePropertyFilter,@@ -18,7 +18,7 @@ from ee.hogai.summarizers.property_filters import ()-class TestPropertyFilterDescriber(BaseTest):+class TestPropertyFilterDescriber(SimpleTestCase):def test_event_property_filter(self):# No taxonomyfilter = EventPropertyFilter(key="prop", operator="exact", value="test")@@ -136,7 +136,7 @@ class TestPropertyFilterDescriber(BaseTest):self.assertIn("DataWarehousePropertyFilter", str(context.exception))-class TestPropertyFilterCollectionDescriber(BaseTest):+class TestPropertyFilterCollectionDescriber(SimpleTestCase):def test_multiple_property_filters(self):# Create filtersevent_filter = EventPropertyFilter(key="$current_url", operator=PropertyOperator.NOT_ICONTAINS, value="url")diff --git a/ee/hogai/test/test_registry.py b/ee/hogai/test/test_registry.pyindex 52073f016e64..416c94cc0935 100644--- a/ee/hogai/test/test_registry.py+++ b/ee/hogai/test/test_registry.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import AssistantTool-class TestToolRegistry(BaseTest):+class TestToolRegistry(SimpleTestCase):def test_can_get_registered_contextual_tool_class(self):from ee.hogai.registry import get_contextual_tool_classdiff --git a/ee/hogai/test/test_schema.py b/ee/hogai/test/test_schema.pyindex d58ff19d1b01..c4b7cdc4314e 100644--- a/ee/hogai/test/test_schema.py+++ b/ee/hogai/test/test_schema.py@@ -1,11 +1,11 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom pydantic import ValidationErrorfrom posthog.schema import AssistantFunnelsQuery, AssistantRetentionQuery, AssistantTrendsQuery-class TestSchema(BaseTest):+class TestSchema(SimpleTestCase):def test_schema_series_properties_do_not_accept_arbitrary_strings(self):"""If this test fails, check the schema of `series.properties[].type`. It must be an enum."""diff --git a/ee/hogai/test/test_tool.py b/ee/hogai/test/test_tool.pyindex 14e40b88fb90..af9ef63215c9 100644--- a/ee/hogai/test/test_tool.py+++ b/ee/hogai/test/test_tool.py@@ -2,6 +2,8 @@ import pytestfrom posthog.test.base import BaseTestfrom unittest.mock import patch+from django.test import SimpleTestCase+from langgraph.errors import GraphInterruptfrom pydantic import BaseModel@@ -195,7 +197,7 @@ class TestMaxToolClientExecution(BaseTest):tool.request_client_execution()-class TestMaxToolErrorHierarchy(BaseTest):+class TestMaxToolErrorHierarchy(SimpleTestCase):"""Test the MaxToolError exception hierarchy and retry strategies."""def test_max_tool_error_base_has_never_retry_strategy(self):@@ -322,7 +324,7 @@ class TestMaxToolErrorHierarchy(BaseTest):self.assertEqual(summary, "MaxToolFatalError: Error with whitespace")-class TestMaxToolAccessDeniedError(BaseTest):+class TestMaxToolAccessDeniedError(SimpleTestCase):"""Test the MaxToolAccessDeniedError exception."""def test_access_denied_error_formats_correctly(self):diff --git a/ee/hogai/test/test_utils.py b/ee/hogai/test/test_utils.pyindex 83a30b607dc0..998ba3c20d04 100644--- a/ee/hogai/test/test_utils.py+++ b/ee/hogai/test/test_utils.py@@ -1,4 +1,4 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.schema import ArtifactContentType, ArtifactSource, AssistantMessage, FailureMessage, HumanMessage@@ -6,7 +6,7 @@ from ee.hogai.utils.helpers import filter_and_merge_messagesfrom ee.hogai.utils.types.base import ArtifactRefMessage, AssistantMessageUnion-class TestTrendsUtils(BaseTest):+class TestTrendsUtils(SimpleTestCase):def test_filters_and_merges_human_messages(self):conversation: list[AssistantMessageUnion] = [HumanMessage(content="Text"),diff --git a/ee/hogai/tools/create_notebook/test/test_parsing.py b/ee/hogai/tools/create_notebook/test/test_parsing.pyindex dbdfd875e7d3..8f5a65505ae0 100644--- a/ee/hogai/tools/create_notebook/test/test_parsing.py+++ b/ee/hogai/tools/create_notebook/test/test_parsing.py@@ -1,5 +1,7 @@from posthog.test.base import BaseTest+from django.test import SimpleTestCase+from parameterized import parameterizedfrom posthog.schema import LoadingBlock, MarkdownBlock@@ -120,7 +122,7 @@ class TestParseNotebookContentForStreaming(BaseTest):assert "More text" in result[2].content-class TestStripIncompleteInsightTags(BaseTest):+class TestStripIncompleteInsightTags(SimpleTestCase):@parameterized.expand([("text<i", "text"),@@ -192,7 +194,7 @@ class TestStripIncompleteInsightTags(BaseTest):assert result == ""-class TestStripTitleHeading(BaseTest):+class TestStripTitleHeading(SimpleTestCase):@parameterized.expand([("# My Title\n\nContent", "My Title", "Content"),@@ -226,7 +228,7 @@ class TestStripTitleHeading(BaseTest):assert result == content-class TestParseNotebookContentForStorageWithTitle(BaseTest):+class TestParseNotebookContentForStorageWithTitle(SimpleTestCase):def test_matching_title_removed_from_first_block(self):content = "# My Notebook\n\nHere's the chart:\n\n<insight>chart1</insight>"result = parse_notebook_content_for_storage(content, title="My Notebook")diff --git a/ee/hogai/tools/test/test_todo_write.py b/ee/hogai/tools/test/test_todo_write.pyindex 938ca56055d9..95854e4c6ef9 100644--- a/ee/hogai/tools/test/test_todo_write.py+++ b/ee/hogai/tools/test/test_todo_write.py@@ -1,11 +1,11 @@from typing import Any-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom ee.hogai.tools.todo_write import TodoItem, TodoWriteTool-class TestTodoWriteTool(BaseTest):+class TestTodoWriteTool(SimpleTestCase):def test_format_todo_list_empty_list(self):"""Test formatting an empty todo list from list"""result = TodoWriteTool.format_todo_list([])diff --git a/ee/hogai/utils/test/test_anthropic.py b/ee/hogai/utils/test/test_anthropic.pyindex bc9d481f2bab..0c6b00e2c5e3 100644--- a/ee/hogai/utils/test/test_anthropic.py+++ b/ee/hogai/utils/test/test_anthropic.py@@ -1,4 +1,4 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom langchain_core.messages import AIMessage, HumanMessagefrom parameterized import parameterized@@ -21,7 +21,7 @@ from ee.hogai.utils.anthropic import ()-class TestAnthropicUtils(BaseTest):+class TestAnthropicUtils(SimpleTestCase):@parameterized.expand([(None, []),diff --git a/ee/hogai/utils/test/test_assistant_helpers.py b/ee/hogai/utils/test/test_assistant_helpers.pyindex b6f6e4b86816..d27f09bc6b01 100644--- a/ee/hogai/utils/test/test_assistant_helpers.py+++ b/ee/hogai/utils/test/test_assistant_helpers.py@@ -1,7 +1,8 @@from collections.abc import Sequenceimport unittest-from posthog.test.base import BaseTest++from django.test import SimpleTestCasefrom langchain_core.messages import AIMessage, AIMessageChunkfrom parameterized import parameterized@@ -31,7 +32,7 @@ from ee.hogai.utils.helpers import (from ee.hogai.utils.types.base import AssistantMessageUnion-class TestAssistantHelpers(BaseTest):+class TestAssistantHelpers(SimpleTestCase):def test_should_output_assistant_message(self):"""Test that the should_output_assistant_message filter works correctly:@@ -172,7 +173,7 @@ class TestAssistantHelpers(BaseTest):self.assertEqual(result, expected_message)-class TestNormalizeAIMessage(BaseTest):+class TestNormalizeAIMessage(SimpleTestCase):def test_normalize_ai_message_with_string_content(self):"""Test normalizing AIMessage with simple string content"""message = AIMessage(@@ -324,7 +325,7 @@ class TestNormalizeAIMessage(BaseTest):self.assertEqual(result.meta.thinking[0]["type"], "thinking")-class TestExtractThinkingFromAIMessage(BaseTest):+class TestExtractThinkingFromAIMessage(SimpleTestCase):"""Test extract_thinking_from_ai_message with various formats."""def test_extract_thinking_from_anthropic_format(self):@@ -417,7 +418,7 @@ class TestExtractThinkingFromAIMessage(BaseTest):self.assertEqual(thinking[1]["content"], "Thought 2")-class TestConvertToolMessagesToDict(BaseTest):+class TestConvertToolMessagesToDict(SimpleTestCase):"""Test convert_tool_messages_to_dict function."""def test_convert_single_tool_message(self):@@ -479,7 +480,7 @@ class TestConvertToolMessagesToDict(BaseTest):self.assertEqual(result["tc1"].ui_payload, {"data": "value"})-class TestNormalizeAIMessageWebSearch(BaseTest):+class TestNormalizeAIMessageWebSearch(SimpleTestCase):"""Test normalize_ai_message with web search and server tool use blocks."""def test_normalize_with_server_tool_use(self):@@ -717,7 +718,7 @@ class TestStripBkDrilldownHandles(unittest.TestCase):assert strip_bk_drilldown_handles(text) == expected-class TestNormalizeAiMessageStripsHandles(BaseTest):+class TestNormalizeAiMessageStripsHandles(SimpleTestCase):def test_handles_stripped_from_text_content(self) -> None:from ee.hogai.utils.helpers import normalize_ai_messagediff --git a/ee/hogai/utils/test/test_assistant_types.py b/ee/hogai/utils/test/test_assistant_types.pyindex f02579f5b93f..1e8d53574ddd 100644--- a/ee/hogai/utils/test/test_assistant_types.py+++ b/ee/hogai/utils/test/test_assistant_types.py@@ -3,6 +3,8 @@ from uuid import uuid4from posthog.test.base import BaseTest+from django.test import SimpleTestCase+from langchain_core.messages import AIMessagefrom langgraph.graph import END, START, StateGraphfrom parameterized import parameterized@@ -23,7 +25,7 @@ from ee.hogai.utils.types import AssistantState, PartialAssistantState, add_and_from ee.hogai.utils.types.base import ArtifactRefMessage, ReplaceMessages-class TestAssistantTypes(BaseTest):+class TestAssistantTypes(SimpleTestCase):"""Test the assistant types."""def test_merge_messages_with_same_id(self):@@ -158,7 +160,7 @@ class TestArtifactRefMessage(BaseTest):self.assertEqual(message.content_type, ArtifactContentType.VISUALIZATION)-class TestIsVisualizationArtifactMessage(BaseTest):+class TestIsVisualizationArtifactMessage(SimpleTestCase):def test_returns_true_for_visualization_artifact_message(self):content = VisualizationArtifactContent(query=AssistantTrendsQuery(series=[]),@@ -322,7 +324,7 @@ class TestConvertVisualizationMessagesToArtifacts(BaseTest):self.assertNotEqual(viz.id, artifact.id)-class TestUnwrapVisualizationArtifactContent(BaseTest):+class TestUnwrapVisualizationArtifactContent(SimpleTestCase):def test_returns_content_for_visualization_artifact_message(self):content = VisualizationArtifactContent(query=AssistantTrendsQuery(series=[]),diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex 991604014119..79d3ea4994a5 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -30,33 +30,6 @@ ee/hogai/context/insight/format/test/test_stickiness.py::TestStickinessResultsFoee/hogai/context/insight/format/test/test_utils.py::TestFormatUtilsee/hogai/context/insight/test/test_query_executor.py::TestValidateAssistantQueryee/hogai/core/plan_mode/test/test_executables.py::TestSupermodeReducer-ee/hogai/core/test/test_artifacts.py::TestDocumentArtifactContent-ee/hogai/core/test/test_artifacts.py::TestDocumentBlocks-ee/hogai/core/test/test_artifacts.py::TestVisualizationArtifactContent-ee/hogai/core/test/test_base_callback_handlers.py::TestSubagentCallbackHandler-ee/hogai/core/test/test_dispatcher_integration.py::TestDispatcherIntegration-ee/hogai/research_agent/test/test_runner.py::TestResearchAgentRunnerConfiguration-ee/hogai/summarizers/test/test_property_filters.py::TestPropertyFilterCollectionDescriber-ee/hogai/summarizers/test/test_property_filters.py::TestPropertyFilterDescriber-ee/hogai/test/test_registry.py::TestToolRegistry-ee/hogai/test/test_schema.py::TestSchema-ee/hogai/test/test_tool.py::TestMaxToolAccessDeniedError-ee/hogai/test/test_tool.py::TestMaxToolErrorHierarchy-ee/hogai/test/test_utils.py::TestTrendsUtils-ee/hogai/tools/create_notebook/test/test_parsing.py::TestParseNotebookContentForStorageWithTitle-ee/hogai/tools/create_notebook/test/test_parsing.py::TestStripIncompleteInsightTags-ee/hogai/tools/create_notebook/test/test_parsing.py::TestStripTitleHeading-ee/hogai/tools/test/test_todo_write.py::TestTodoWriteTool-ee/hogai/utils/test/test_anthropic.py::TestAnthropicUtils-ee/hogai/utils/test/test_assistant_helpers.py::TestAssistantHelpers-ee/hogai/utils/test/test_assistant_helpers.py::TestConvertToolMessagesToDict-ee/hogai/utils/test/test_assistant_helpers.py::TestExtractThinkingFromAIMessage-ee/hogai/utils/test/test_assistant_helpers.py::TestNormalizeAIMessage-ee/hogai/utils/test/test_assistant_helpers.py::TestNormalizeAIMessageWebSearch-ee/hogai/utils/test/test_assistant_helpers.py::TestNormalizeAiMessageStripsHandles-ee/hogai/utils/test/test_assistant_types.py::TestAssistantTypes-ee/hogai/utils/test/test_assistant_types.py::TestIsVisualizationArtifactMessage-ee/hogai/utils/test/test_assistant_types.py::TestUnwrapVisualizationArtifactContentee/hogai/utils/test/test_dispatcher.py::TestDispatcherIntegrationee/hogai/utils/test/test_openai.py::TestOpenAIUtilsee/partners/stripe/api/provisioning/test/test_services_catalog.py::TestServicesCatalog