: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(batch-exports): deselect vendor credential tests in CI (#99308)
Georges-Antoine Assi4f25a6e5ae4d
diff --git a/posthog/conftest.py b/posthog/conftest.pyindex 78f0c214890e..74787aa96bce 100644--- a/posthog/conftest.py+++ b/posthog/conftest.py@@ -21,6 +21,7 @@ from django.core.management.commands.flush import Command as FlushCommandfrom infi.clickhouse_orm import Databasefrom posthog.clickhouse.client import sync_execute+from posthog.cloud_utils import is_cifrom posthog.test import flush_lock_guard@@ -641,6 +642,41 @@ def pytest_runtest_setup(item: pytest.Item) -> None:pytest.skip("Skipping test that requires internal secrets on external PRs")+def _vendor_credentials_present(marker: pytest.Mark) -> bool:+ check: Callable[[], bool] | None = marker.kwargs.get("check")+ return all(name in os.environ for name in marker.args) and (check is None or check())+++def _describe_vendor_credentials(marker: pytest.Mark) -> str:+ check: Callable[[], bool] | None = marker.kwargs.get("check")+ return ", ".join([*marker.args, *([check.__name__] if check is not None else [])])+++def _gate_vendor_credential_tests(config: pytest.Config, items: list[pytest.Item]) -> None:+ """Deselect vendor credential tests in CI, where they can only skip and a skip with no recorded+ pass reads as a broken test. Locally they stay collected, because a developer may export the+ credentials, and skip with a reason naming what is missing.+ """+ gated = [+ (item, marker)+ for item in items+ if (marker := item.get_closest_marker("requires_vendor_credentials")) is not None+ ]+ if not gated:+ return+ if is_ci():+ deselected = {id(item) for item, _ in gated}+ config.hook.pytest_deselected(items=[item for item, _ in gated])+ items[:] = [item for item in items if id(item) not in deselected]+ return+ for item, marker in gated:+ if not _vendor_credentials_present(marker):+ item.add_marker(+ pytest.mark.skip(reason=f"vendor credentials not available: {_describe_vendor_credentials(marker)}")+ )++def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:if apply_quarantine_markers is not None:apply_quarantine_markers(items)+ _gate_vendor_credential_tests(config, items)diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.py b/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.pyindex 7bf1ad518e96..0ca54d890ac7 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.py+++ b/products/batch_exports/backend/tests/api/destination_tests/test_bigquery_destination_tests.py@@ -29,9 +29,8 @@ from products.batch_exports.backend.tests.temporal.destinations.s3.utils importcheck_valid_credentials as has_valid_aws_credentials,)-SKIP_IF_MISSING_GOOGLE_APPLICATION_CREDENTIALS = pytest.mark.skipif(- "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ,- reason="Google credentials not set in environment",+SKIP_IF_MISSING_GOOGLE_APPLICATION_CREDENTIALS = pytest.mark.requires_vendor_credentials(+ "GOOGLE_APPLICATION_CREDENTIALS")pytestmark = [SKIP_IF_MISSING_GOOGLE_APPLICATION_CREDENTIALS, pytest.mark.asyncio]diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.py b/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.pyindex c551510e2f26..489843079893 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.py+++ b/products/batch_exports/backend/tests/api/destination_tests/test_databricks_destination_tests.py@@ -28,11 +28,8 @@ REQUIRED_ENV_VARS = (pytestmark = [+ pytest.mark.requires_vendor_credentials(*REQUIRED_ENV_VARS),pytest.mark.django_db,- pytest.mark.skipif(- not all(env_var in os.environ for env_var in REQUIRED_ENV_VARS),- reason=f"Databricks required env vars are not set: {', '.join(REQUIRED_ENV_VARS)}",- ),]diff --git a/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.py b/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.pyindex 6533b4615aa0..3d0d0ca26d9c 100644--- a/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.py+++ b/products/batch_exports/backend/tests/api/destination_tests/test_snowflake_destination_tests.py@@ -29,10 +29,7 @@ def snowflake_env_vars_are_set():return True-SKIP_IF_MISSING_REQUIRED_ENV_VARS = pytest.mark.skipif(- not snowflake_env_vars_are_set(),- reason="Snowflake required env vars are not set",-)+SKIP_IF_MISSING_REQUIRED_ENV_VARS = pytest.mark.requires_vendor_credentials(check=snowflake_env_vars_are_set)pytestmark = [SKIP_IF_MISSING_REQUIRED_ENV_VARS, pytest.mark.asyncio]diff --git a/products/batch_exports/backend/tests/temporal/destinations/azure_blob/test_workflow_with_azure_account.py b/products/batch_exports/backend/tests/temporal/destinations/azure_blob/test_workflow_with_azure_account.pyindex 28f84c325d3f..ed4cbb15c3f0 100644--- a/products/batch_exports/backend/tests/temporal/destinations/azure_blob/test_workflow_with_azure_account.py+++ b/products/batch_exports/backend/tests/temporal/destinations/azure_blob/test_workflow_with_azure_account.py@@ -32,12 +32,9 @@ from products.batch_exports.backend.tests.temporal.destinations.azure_blob.utils)pytestmark = [+ pytest.mark.requires_vendor_credentials("AZURE_STORAGE_CONNECTION_STRING", "AZURE_TEST_CONTAINER"),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- "AZURE_STORAGE_CONNECTION_STRING" not in os.environ or "AZURE_TEST_CONTAINER" not in os.environ,- reason="Real Azure credentials not set (AZURE_STORAGE_CONNECTION_STRING and AZURE_TEST_CONTAINER required)",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py b/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.pyindex ea1bcd4fecb8..aac89b9bc2b3 100644--- a/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py+++ b/products/batch_exports/backend/tests/temporal/destinations/bigquery/utils.py@@ -1,4 +1,3 @@-import osimport jsonimport asyncioimport datetime as dt@@ -22,9 +21,8 @@ from products.batch_exports.backend.temporal.record_batch_model import SessionsRfrom products.batch_exports.backend.tests.temporal.utils.clickhouse_test_producer import ClickHouseTestProducerfrom products.batch_exports.backend.tests.temporal.utils.records import get_record_batch_from_queue-SKIP_IF_MISSING_GOOGLE_APPLICATION_CREDENTIALS = pytest.mark.skipif(- "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ,- reason="Google credentials not set in environment",+SKIP_IF_MISSING_GOOGLE_APPLICATION_CREDENTIALS = pytest.mark.requires_vendor_credentials(+ "GOOGLE_APPLICATION_CREDENTIALS")TEST_TIME = dt.datetime.now(dt.UTC).replace(hour=0, minute=0, second=0, microsecond=0)diff --git a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_client.py b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_client.pyindex 5b8f38efdea7..b7fd6a856982 100644--- a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_client.py+++ b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_client.py@@ -26,10 +26,7 @@ REAL_DATABRICKS_ENV_VARS = ("DATABRICKS_BE_CLIENT_SECRET",)-skip_without_real_databricks = pytest.mark.skipif(- not all(env_var in os.environ for env_var in REAL_DATABRICKS_ENV_VARS),- reason=f"Databricks required env vars are not set: {', '.join(REAL_DATABRICKS_ENV_VARS)}",-)+skip_without_real_databricks = pytest.mark.requires_vendor_credentials(*REAL_DATABRICKS_ENV_VARS)@pytest.fixturediff --git a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.pyindex 0de4f6a2cc96..cc6051fa3841 100644--- a/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py+++ b/products/batch_exports/backend/tests/temporal/destinations/databricks/test_workflow.py@@ -53,11 +53,8 @@ REQUIRED_ENV_VARS = (pytestmark = [+ pytest.mark.requires_vendor_credentials(*REQUIRED_ENV_VARS),pytest.mark.django_db,- pytest.mark.skipif(- not all(env_var in os.environ for env_var in REQUIRED_ENV_VARS),- reason=f"Databricks required env vars are not set: {', '.join(REQUIRED_ENV_VARS)}",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_activity.py b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_activity.pyindex b9bba0152a8a..030c5df8caeb 100644--- a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_activity.py+++ b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_activity.py@@ -30,12 +30,9 @@ from products.batch_exports.backend.tests.temporal.destinations.s3.utils import)pytestmark = [+ pytest.mark.requires_vendor_credentials(check=has_valid_credentials),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- not has_valid_credentials(),- reason="AWS credentials not set in environment",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_workflow.pyindex 53da5fddda5f..64013a143eb7 100644--- a/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_workflow.py+++ b/products/batch_exports/backend/tests/temporal/destinations/file_download/test_file_download_workflow.py@@ -30,10 +30,7 @@ from products.batch_exports.backend.tests.temporal.utils.workflow import fail_onpytestmark = [pytest.mark.asyncio, pytest.mark.django_db]-requires_aws_credentials = pytest.mark.skipif(- not has_valid_credentials(),- reason="AWS credentials not set in environment",-)+requires_aws_credentials = pytest.mark.requires_vendor_credentials(check=has_valid_credentials)@pytest_asyncio.fixturediff --git a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_copy_activity.py b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_copy_activity.pyindex b4862e7c05f5..1be96979384e 100644--- a/products/batch_exports/backend/tests/temporal/destinations/redshift/test_copy_activity.py+++ b/products/batch_exports/backend/tests/temporal/destinations/redshift/test_copy_activity.py@@ -1,4 +1,3 @@-import osimport uuidimport datetime as dt@@ -26,6 +25,7 @@ from products.batch_exports.backend.temporal.pipeline.internal_stage import ()from products.batch_exports.backend.tests.temporal.destinations.redshift.utils import (MISSING_REQUIRED_ENV_VARS,+ REQUIRED_ENV_VARS,TEST_MODELS,assert_clickhouse_records_in_redshift,)@@ -37,12 +37,9 @@ from products.batch_exports.backend.tests.temporal.utils.persons import (from products.batch_exports.backend.tests.temporal.utils.s3 import delete_all_from_s3pytestmark = [+ pytest.mark.requires_vendor_credentials("S3_TEST_BUCKET", *REQUIRED_ENV_VARS, check=has_valid_credentials),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- "S3_TEST_BUCKET" not in os.environ or not has_valid_credentials() or MISSING_REQUIRED_ENV_VARS,- reason="AWS credentials not set in environment or missing S3_TEST_BUCKET variable",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_gcs_bucket.py b/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_gcs_bucket.pyindex 2dae3c5fc36e..7c4bf983ed57 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_gcs_bucket.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_gcs_bucket.py@@ -21,7 +21,6 @@ from products.batch_exports.backend.tests.temporal.destinations.s3.utils importSUPPORTED_FILE_FORMAT_COMPRESSIONS,TEST_S3_MODELS,assert_clickhouse_records_in_s3,- has_valid_gcs_credentials,run_activity,)from products.batch_exports.backend.tests.temporal.utils.s3 import (@@ -31,12 +30,9 @@ from products.batch_exports.backend.tests.temporal.utils.s3 import ()pytestmark = [+ pytest.mark.requires_vendor_credentials("GCS_TEST_BUCKET", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- not has_valid_gcs_credentials(),- reason="GCS credentials (AWS keys) not set in environment or missing GCS_TEST_BUCKET variable",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_role_assumption.py b/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_role_assumption.pyindex 4d1b1dd53ddc..89293b9e68e4 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_role_assumption.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/test_activity_with_role_assumption.py@@ -25,9 +25,7 @@ from products.batch_exports.backend.tests.temporal.destinations.s3.utils importrun_activity,)-pytestmark = [- pytest.mark.skipif(not has_valid_credentials(), reason="AWS credentials not set in environment"),-]+pytestmark = [pytest.mark.requires_vendor_credentials(check=has_valid_credentials)]@pytest.fixture(scope="module")diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_gcs_bucket.py b/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_gcs_bucket.pyindex 1c66ddb54260..747b0356987a 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_gcs_bucket.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_gcs_bucket.py@@ -13,19 +13,13 @@ from products.batch_exports.backend.temporal.destinations.s3_batch_export importFILE_FORMAT_EXTENSIONS,SUPPORTED_COMPRESSIONS,)-from products.batch_exports.backend.tests.temporal.destinations.s3.utils import (- has_valid_gcs_credentials,- run_s3_batch_export_workflow,-)+from products.batch_exports.backend.tests.temporal.destinations.s3.utils import run_s3_batch_export_workflowfrom products.batch_exports.backend.tests.temporal.utils.s3 import delete_all_from_s3pytestmark = [+ pytest.mark.requires_vendor_credentials("GCS_TEST_BUCKET", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- not has_valid_gcs_credentials(),- reason="GCS credentials (AWS keys) not set in environment or missing GCS_TEST_BUCKET variable",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_s3_bucket.py b/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_s3_bucket.pyindex 20cc1da76a4f..4951bf83f2f4 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_s3_bucket.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/test_workflow_with_s3_bucket.py@@ -23,12 +23,9 @@ from products.batch_exports.backend.tests.temporal.destinations.s3.utils importfrom products.batch_exports.backend.tests.temporal.utils.s3 import delete_all_from_s3pytestmark = [+ pytest.mark.requires_vendor_credentials("S3_TEST_BUCKET", check=has_valid_credentials),pytest.mark.asyncio,pytest.mark.django_db,- pytest.mark.skipif(- "S3_TEST_BUCKET" not in os.environ or not has_valid_credentials(),- reason="AWS credentials not set in environment or missing S3_TEST_BUCKET variable",- ),]diff --git a/products/batch_exports/backend/tests/temporal/destinations/s3/utils.py b/products/batch_exports/backend/tests/temporal/destinations/s3/utils.pyindex 4a2afdd5944f..1ee49a79caa0 100644--- a/products/batch_exports/backend/tests/temporal/destinations/s3/utils.py+++ b/products/batch_exports/backend/tests/temporal/destinations/s3/utils.py@@ -1,10 +1,10 @@-import osimport jsonimport uuidimport typing as timport asyncioimport datetime as dtimport operator+import functoolsimport dataclassesfrom django.conf import settings@@ -137,6 +137,7 @@ async def check_valid_credentials() -> bool:return Truedef has_valid_credentials() -> bool:"""Synchronous wrapper around check_valid_credentials."""return asyncio.run(check_valid_credentials())@@ -503,9 +504,3 @@ async def run_activity(activity_environment: ActivityEnvironment, insert_inputs:result = await activity_environment.run(insert_into_s3_activity_from_stage, insert_inputs)return result---def has_valid_gcs_credentials() -> bool:- return (- "GCS_TEST_BUCKET" in os.environ and "AWS_ACCESS_KEY_ID" in os.environ and "AWS_SECRET_ACCESS_KEY" in os.environ- )diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.pyindex 3d8de3583876..68a306f162cb 100644--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py@@ -46,10 +46,7 @@ def snowflake_env_vars_are_set():return True-SKIP_IF_MISSING_REQUIRED_ENV_VARS = pytest.mark.skipif(- not snowflake_env_vars_are_set(),- reason="Snowflake required env vars are not set",-)+SKIP_IF_MISSING_REQUIRED_ENV_VARS = pytest.mark.requires_vendor_credentials(check=snowflake_env_vars_are_set)EXPECTED_PERSONS_BATCH_EXPORT_FIELDS = ["team_id",diff --git a/pytest.ini b/pytest.iniindex 5edbf10828c8..a44e5465bf09 100644--- a/pytest.ini+++ b/pytest.ini@@ -30,6 +30,7 @@ markers =skip_on_multitenancyasync_migrationsrequires_secrets: test needs internal secrets or infra and is skipped on external PRs+ requires_vendor_credentials(*env_vars, check=None): test talks to a real cloud vendor; CI deselects it, local runs skip it unless every env var is set and check() passesquarantine: applied automatically to tests quarantined via .test_quarantine.json (hogli test:quarantine)persons_db_direct: test exercises the persons DB directly and must not have the personhog fake / ORM block active