: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 core service tests (part 1) (#116224)
Paul D'Ambra643d27268863
diff --git a/posthog/admin/test_admin.py b/posthog/admin/test_admin.pyindex 6222f07d5ae5..e0f0a6243464 100644--- a/posthog/admin/test_admin.py+++ b/posthog/admin/test_admin.py@@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patchfrom django.contrib import adminfrom django.contrib.admin import AdminSite-from django.test import RequestFactory+from django.test import RequestFactory, SimpleTestCasefrom posthog.admin import _OAUTH_ADMIN_MODEL_NAMES, install_admin_app_list_overrides, register_all_adminfrom posthog.admin.admins.event_ingestion_restriction_config import EventIngestionRestrictionConfigAdmin@@ -31,7 +31,7 @@ from products.surveys.backend.models import Surveyfrom products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSchema-class TestOAuthSidebarRegrouping(BaseTest):+class TestOAuthSidebarRegrouping(SimpleTestCase):def _patched_get_app_list(self):site = AdminSite()site.get_app_list = lambda request, app_label=None: [ # type: ignore[method-assign] # ty: ignore[invalid-assignment]@@ -136,7 +136,7 @@ class TestUserAdmin(BaseTest):form.clean_passkeys_enabled_for_2fa()-class TestPluginAttachmentInline(BaseTest):+class TestPluginAttachmentInline(SimpleTestCase):def test_parsed_json_escapes_html_in_values(self):inline = PluginAttachmentInline(MagicMock(), MagicMock())attachment = MagicMock()@@ -240,7 +240,7 @@ class TestProductAdminRegistration:assert admin.site.is_registered(model), f"{model.__name__} is not registered in Django admin"-class TestOrganizationMemberInlineConfig(BaseTest):+class TestOrganizationMemberInlineConfig(SimpleTestCase):def test_invited_by_is_readonly_and_never_rendered_as_user_select(self):# Regression guard: invited_by must not become an editable FK select in admin inlines.assert "invited_by" in OrganizationMemberInline.fieldsdiff --git a/posthog/caching/test/test_redis_cluster_keys.py b/posthog/caching/test/test_redis_cluster_keys.pyindex 74aecc206d57..9a0375161b26 100644--- a/posthog/caching/test/test_redis_cluster_keys.py+++ b/posthog/caching/test/test_redis_cluster_keys.py@@ -1,13 +1,14 @@-from posthog.test.base import BaseTestfrom unittest.mock import MagicMock+from django.test import SimpleTestCase+from parameterized import parameterizedfrom redis.crc import key_slotfrom posthog.query_cache.size_tracker import TeamCacheSizeTracker-class TestRedisClusterKeySlots(BaseTest):+class TestRedisClusterKeySlots(SimpleTestCase):@parameterized.expand([("team_1", 1),diff --git a/posthog/helpers/test_markdown_safety.py b/posthog/helpers/test_markdown_safety.pyindex 2e37649eb30a..3f64fd38c38d 100644--- a/posthog/helpers/test_markdown_safety.py+++ b/posthog/helpers/test_markdown_safety.py@@ -1,12 +1,13 @@import pytest-from posthog.test.base import BaseTest++from django.test import SimpleTestCasefrom parameterized import parameterizedfrom posthog.helpers.markdown_safety import strip_external_links_markdown-class TestStripExternalLinks(BaseTest):+class TestStripExternalLinks(SimpleTestCase):@parameterized.expand([("no_title", "[x](https://evil.example.com)"),diff --git a/posthog/helpers/tests/test_encrypted_fields.py b/posthog/helpers/tests/test_encrypted_fields.pyindex 6cb2c7bfbb02..891ab617f348 100644--- a/posthog/helpers/tests/test_encrypted_fields.py+++ b/posthog/helpers/tests/test_encrypted_fields.py@@ -1,7 +1,6 @@import base64import time_machine-from posthog.test.base import BaseTestfrom unittest.mock import patchfrom django.test import SimpleTestCase, override_settings@@ -59,7 +58,7 @@ def _decrypt_with(keys: list[str], token: str) -> str:return EncryptedFieldMixin().decrypt(token)-class TestEncryptedFields(BaseTest):+class TestEncryptedFields(SimpleTestCase):def test_simple_encryption_and_decryption(self):"""Simple test case to be replicated in node tests or anywhere else that the same secrets will be useddiff --git a/posthog/helpers/tests/test_geoip.py b/posthog/helpers/tests/test_geoip.pyindex 52e5997a9467..c1b6634ff47c 100644--- a/posthog/helpers/tests/test_geoip.py+++ b/posthog/helpers/tests/test_geoip.py@@ -4,7 +4,7 @@ import pytestfrom unittest.mock import Mockfrom django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception-from django.test import TestCase+from django.test import SimpleTestCasefrom posthog.geoip import geoip, get_geoip_properties@@ -36,7 +36,7 @@ def test_geoip_results(test_input, expected_country):assert len(properties) >= 5-class TestGeoIPDBError(TestCase):+class TestGeoIPDBError(SimpleTestCase):def setUp(self) -> None:self.geoip_city_method = cast(GeoIP2, geoip).citygeoip.city = Mock(side_effect=GeoIP2Exception("GeoIP file not found")) # type: ignore@@ -50,7 +50,7 @@ class TestGeoIPDBError(TestCase):self.assertEqual(properties, {})-class TestGeoIPError(TestCase):+class TestGeoIPError(SimpleTestCase):def test_geoip_on_localhost_ip_returns_successfully(self):properties = get_geoip_properties(localhost_ip)diff --git a/posthog/hogql_queries/ai/test/test_utils.py b/posthog/hogql_queries/ai/test/test_utils.pyindex 17a7f329028f..1202455bad5d 100644--- a/posthog/hogql_queries/ai/test/test_utils.py+++ b/posthog/hogql_queries/ai/test/test_utils.py@@ -2,7 +2,7 @@ from datetime import timedeltafrom posthog.test.base import BaseTest-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.utils import timezoneimport orjson@@ -36,7 +36,7 @@ class TestTaxonomyUtils(BaseTest):self.assertTrue(mixin._is_stale(last_refresh=date - timedelta(minutes=60), lazy=False))-class TestMergeHeavyProperties(BaseTest):+class TestMergeHeavyProperties(SimpleTestCase):def test_merges_heavy_columns_into_properties(self):props_json = orjson.dumps({"$ai_model": "gpt-4", "$browser": "Chrome"}).decode()heavy = {@@ -101,7 +101,7 @@ class TestMergeHeavyProperties(BaseTest):self.assertEqual(result, {"$browser": "", "$ai_model": None})-class TestFilledPropertyFilters(BaseTest):+class TestFilledPropertyFilters(SimpleTestCase):@parameterized.expand([("no_value", EventPropertyFilter(key="$ai_span_name", operator=PropertyOperator.EXACT)),diff --git a/posthog/hogql_queries/endpoints/test/test_endpoints_usage_query_runners.py b/posthog/hogql_queries/endpoints/test/test_endpoints_usage_query_runners.pyindex d57432522fa3..74e38ad67fe1 100644--- a/posthog/hogql_queries/endpoints/test/test_endpoints_usage_query_runners.py+++ b/posthog/hogql_queries/endpoints/test/test_endpoints_usage_query_runners.py@@ -1,6 +1,8 @@import time_machinefrom posthog.test.base import APIBaseTest, ClickhouseTestMixin, QueryMatchingTest+from django.test import SimpleTestCase+from parameterized import parameterizedfrom posthog.schema import (@@ -21,7 +23,7 @@ from posthog.hogql_queries.endpoints.endpoints_usage_table import EndpointsUsagefrom posthog.hogql_queries.endpoints.endpoints_usage_trends import EndpointsUsageTrendsQueryRunner-class TestSafeFloat(APIBaseTest):+class TestSafeFloat(SimpleTestCase):@parameterized.expand([(None, 0.0),diff --git a/posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.py b/posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.pyindex 929e19183b85..04b037e938f2 100644--- a/posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.py+++ b/posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.py@@ -1,9 +1,9 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom posthog.hogql_queries.legacy_compatibility.clean_properties import clean_entity_properties, clean_global_properties-class TestCleanGlobalProperties(BaseTest):+class TestCleanGlobalProperties(SimpleTestCase):def test_handles_empty_properties(self):properties: dict = {}@@ -116,7 +116,7 @@ class TestCleanGlobalProperties(BaseTest):)-class TestCleanEntityProperties(BaseTest):+class TestCleanEntityProperties(SimpleTestCase):def test_handles_empty_properties(self):properties: dict = {}diff --git a/posthog/hogql_queries/utils/test/test_formula_ast.py b/posthog/hogql_queries/utils/test/test_formula_ast.pyindex 3f279524f093..f42e15ad08f8 100644--- a/posthog/hogql_queries/utils/test/test_formula_ast.py+++ b/posthog/hogql_queries/utils/test/test_formula_ast.py@@ -1,4 +1,4 @@-from posthog.test.base import APIBaseTest+from django.test import SimpleTestCasefrom parameterized import parameterized@@ -7,7 +7,7 @@ from posthog.hogql.errors import ExposedHogQLErrorfrom posthog.hogql_queries.utils.formula_ast import FormulaAST-class TestFormulaAST(APIBaseTest):+class TestFormulaAST(SimpleTestCase):def _get_formula_ast(self) -> FormulaAST:formula = FormulaAST(data=[[1, 2, 3, 4], [1, 2, 3, 4]])return formuladiff --git a/posthog/hogql_queries/utils/test/test_sampling.py b/posthog/hogql_queries/utils/test/test_sampling.pyindex d78da092c87f..8b84b1851200 100644--- a/posthog/hogql_queries/utils/test/test_sampling.py+++ b/posthog/hogql_queries/utils/test/test_sampling.py@@ -1,9 +1,9 @@-from django.test import TestCase+from django.test import SimpleTestCasefrom posthog.hogql_queries.utils.sampling import correct_result_for_sampling-class TestQueriesUtil(TestCase):+class TestQueriesUtil(SimpleTestCase):def test_correct_resullt_for_sampling(self):res = correct_result_for_sampling(1, 0.1, None)self.assertEqual(res, 10)diff --git a/posthog/kafka_client/test/test_client.py b/posthog/kafka_client/test/test_client.pyindex 6020d8fd0b57..9677afde4647 100644--- a/posthog/kafka_client/test/test_client.py+++ b/posthog/kafka_client/test/test_client.py@@ -5,7 +5,7 @@ import uuidimport pytestfrom unittest.mock import MagicMock, patch-from django.test import TestCase, override_settings+from django.test import SimpleTestCase, TestCase, override_settingsfrom parameterized import parameterized@@ -261,7 +261,7 @@ _ROUNDTRIP = os.environ.get("KAFKA_ROUNDTRIP_TESTS") == "1"@pytest.mark.skipif(not _ROUNDTRIP, reason="KAFKA_ROUNDTRIP_TESTS=1 required to hit a real broker")@override_settings(TEST=False)-class KafkaClientRoundtripTestCase(TestCase):+class KafkaClientRoundtripTestCase(SimpleTestCase):"""Exercises `_KafkaProducer` against a real broker. Gated behind KAFKA_ROUNDTRIP_TESTS."""def _make_topic(self) -> str:diff --git a/posthog/management/commands/test/test_base_hypercache_command.py b/posthog/management/commands/test/test_base_hypercache_command.pyindex 01091003efd7..613c06628d01 100644--- a/posthog/management/commands/test/test_base_hypercache_command.py+++ b/posthog/management/commands/test/test_base_hypercache_command.py@@ -16,7 +16,7 @@ from posthog.test.base import BaseTestfrom unittest.mock import MagicMock, patchfrom django.core.management.base import OutputWrapper-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom parameterized import parameterizedfrom redis.exceptions import TimeoutError as RedisTimeoutError@@ -236,7 +236,7 @@ class TestVerifyTeamErrorHandling(BaseTest):@override_settings(FLAGS_REDIS_URL="redis://test", TEST=True)-class TestVerificationResultsErrorReporting(BaseTest):+class TestVerificationResultsErrorReporting(SimpleTestCase):"""Test error reporting in verification results."""def test_error_count_displayed_when_errors_occurred(self):diff --git a/posthog/management/commands/test/test_survey_cohort_bytecode_stl.py b/posthog/management/commands/test/test_survey_cohort_bytecode_stl.pyindex f23412f7183d..ee8b0fb42248 100644--- a/posthog/management/commands/test/test_survey_cohort_bytecode_stl.py+++ b/posthog/management/commands/test/test_survey_cohort_bytecode_stl.py@@ -5,6 +5,7 @@ import tempfilefrom posthog.test.base import BaseTestfrom django.core.management import call_command+from django.test import SimpleTestCasefrom parameterized import parameterized@@ -25,7 +26,7 @@ TRUE, NULL, STRING, INTEGER, RETURN = 29, 31, 32, 33, 38DECLARE_FN, CALLABLE = 41, 52-class TestBytecodeWalker(BaseTest):+class TestBytecodeWalker(SimpleTestCase):@parameterized.expand([(diff --git a/posthog/personhog_client/test_interceptor.py b/posthog/personhog_client/test_interceptor.pyindex 347155e527cc..aa2b60ad17be 100644--- a/posthog/personhog_client/test_interceptor.py+++ b/posthog/personhog_client/test_interceptor.py@@ -1,6 +1,6 @@from __future__ import annotations-from posthog.test.base import BaseTest+from django.test import SimpleTestCaseimport grpcfrom parameterized import parameterized@@ -34,7 +34,7 @@ def _make_call_details()-class TestWithMetadata(BaseTest):+class TestWithMetadata(SimpleTestCase):@parameterized.expand([("no_existing_metadata", None, [("x-key", "val")], [("x-key", "val")]),@@ -68,7 +68,7 @@ class TestWithMetadata(BaseTest):self.assertEqual(result.timeout, details.timeout)-class TestClientNameInterceptor(BaseTest):+class TestClientNameInterceptor(SimpleTestCase):@parameterized.expand([("default_name", "posthog-django"),@@ -93,7 +93,7 @@ class TestClientNameInterceptor(BaseTest):self.assertEqual(metadata["x-client-name"], client_name)-class TestConsistencyHeaderInterceptor(BaseTest):+class TestConsistencyHeaderInterceptor(SimpleTestCase):@parameterized.expand([(diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex 2bbb9ebc1b94..542196e38782 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -3,35 +3,14 @@ ee/clickhouse/materialized_columns/test/test_analyze.py::TestMaterializedColumnsee/clickhouse/models/test/test_dead_letter_queue.py::TestDeadLetterQueueee/clickhouse/models/test/test_property.py::TestPropDenormalizedee/partners/stripe/api/provisioning/test/test_services_catalog.py::TestServicesCatalog-posthog/admin/test_admin.py::TestOAuthSidebarRegrouping-posthog/admin/test_admin.py::TestOrganizationMemberInlineConfig-posthog/admin/test_admin.py::TestPluginAttachmentInlineposthog/api/oauth/test_cimd.py::TestAuthorizationServerMetadata-posthog/caching/test/test_redis_cluster_keys.py::TestRedisClusterKeySlotsposthog/clickhouse/client/test/test_limit.py::TestRateLimitposthog/clickhouse/test/test_deletion_coverage.py::TestDeletionCoverage-posthog/helpers/test_markdown_safety.py::TestStripExternalLinks-posthog/helpers/tests/test_encrypted_fields.py::TestEncryptedFields-posthog/helpers/tests/test_geoip.py::TestGeoIPDBError-posthog/helpers/tests/test_geoip.py::TestGeoIPErrorposthog/hogql/database/test/test_postgres_table.py::TestPostgresTablePrimaryKeyposthog/hogql/printer/test/test_sql_injection_defenses.py::TestEscapePreservationOnParserOutputposthog/hogql/printer/test/test_sql_injection_defenses.py::TestPrintTimeOnlyAllowlistsposthog/hogql/printer/test/test_sql_injection_defenses.py::TestVerbatimFieldPrinterDefenseInDepth-posthog/hogql_queries/ai/test/test_utils.py::TestFilledPropertyFilters-posthog/hogql_queries/ai/test/test_utils.py::TestMergeHeavyProperties-posthog/hogql_queries/endpoints/test/test_endpoints_usage_query_runners.py::TestSafeFloat-posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.py::TestCleanEntityProperties-posthog/hogql_queries/legacy_compatibility/test/test_clean_properties.py::TestCleanGlobalProperties-posthog/hogql_queries/utils/test/test_formula_ast.py::TestFormulaAST-posthog/hogql_queries/utils/test/test_sampling.py::TestQueriesUtil-posthog/kafka_client/test/test_client.py::KafkaClientRoundtripTestCase-posthog/management/commands/test/test_base_hypercache_command.py::TestVerificationResultsErrorReporting-posthog/management/commands/test/test_survey_cohort_bytecode_stl.py::TestBytecodeWalkerposthog/models/tophog/test/test_tophog_queries.py::TestTopHogQueries-posthog/personhog_client/test_interceptor.py::TestClientNameInterceptor-posthog/personhog_client/test_interceptor.py::TestConsistencyHeaderInterceptor-posthog/personhog_client/test_interceptor.py::TestWithMetadataposthog/session_recordings/test/test_session_recording_throttle.py::TestSharingTokenReplayThrottleposthog/session_recordings/test/test_session_recording_throttle.py::TestTierAwareListingThrottleposthog/tasks/test/test_auth_token_cache_verification.py::TestVerifyAndFixAuthTokenCacheTask