From 07b1994c32b8d53ff28c05fea2512b94f924661c Mon Sep 17 00:00:00 2001 From: febux Date: Sun, 6 Sep 2026 21:23:42 +0300 Subject: [PATCH] Fix CI integration tests. --- tests/integration/conftest.py | 5 +++++ tests/integration/test_auth_flow.py | 9 +++++++-- tests/unit/test_worker_billing.py | 14 +++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index d327e47..08f4dad 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -167,6 +167,11 @@ def _set_env() -> None: # `timeout` event). Keep it short so streaming tests finish fast. "SSE_POLL_INTERVAL_SECONDS": "0.25", "SSE_MAX_STREAM_SECONDS": "5", + # CI has no .env, so the Settings default (true) would route + # ExtractHandler to prescreen.q instead of analyze.q. The prescreen + # stage is exercised directly in test_prescreen_worker.py; the + # extract-handler tests assert the analyze.q path. + "PRESCREEN_ENABLED": "false", } for k, v in env_vars.items(): os.environ[k] = v diff --git a/tests/integration/test_auth_flow.py b/tests/integration/test_auth_flow.py index fd03ec2..d34af7a 100644 --- a/tests/integration/test_auth_flow.py +++ b/tests/integration/test_auth_flow.py @@ -8,7 +8,7 @@ from __future__ import annotations import hashlib import hmac import time -from urllib.parse import urlencode +from urllib.parse import urlencode, urlsplit, urlunsplit import httpx import pytest @@ -181,7 +181,12 @@ async def _strict_rate_limit_client() -> httpx.AsyncClient: from contract_check.api.app import create_app from contract_check.core.config import get_settings - isolated_redis_url = "redis://localhost:17379/15" + # Reuse the infra Redis (set by conftest `_set_env`, test-stack port); + # fall back to the dev-stack port for standalone local runs. DB 15 is + # isolated so concurrent/sequential tests do not share buckets. + base_url = os.environ.get("REDIS_URL", "redis://localhost:27379/0") + parts = urlsplit(base_url) + isolated_redis_url = urlunsplit((parts.scheme, parts.netloc, "/15", "", "")) r = redis.from_url(isolated_redis_url) await r.flushdb() await r.aclose() diff --git a/tests/unit/test_worker_billing.py b/tests/unit/test_worker_billing.py index cba19e5..c6a82c1 100644 --- a/tests/unit/test_worker_billing.py +++ b/tests/unit/test_worker_billing.py @@ -74,8 +74,13 @@ class FakeProvider(PaymentProvider): async def factory(): import os - os.environ["DATABASE_URL"] = ( - "postgresql+asyncpg://contract_check:contract_check@localhost:15432/contract_check" + # Integration conftest (_set_env) already points DATABASE_URL at the test + # infra (:25432); only fall back to the dev port when it is unset, and + # restore the previous value afterwards. + prev_url = os.environ.get("DATABASE_URL") + os.environ.setdefault( + "DATABASE_URL", + "postgresql+asyncpg://contract_check:contract_check@localhost:15432/contract_check", ) os.environ["PLANS_ENABLED"] = "true" os.environ["YOOKASSA_ENABLED"] = "true" @@ -85,7 +90,10 @@ async def factory(): get_settings.cache_clear() f = create_session_factory() yield f - os.environ.pop("DATABASE_URL", None) + if prev_url is None: + os.environ.pop("DATABASE_URL", None) + else: + os.environ["DATABASE_URL"] = prev_url os.environ.pop("PLANS_ENABLED", None) os.environ.pop("YOOKASSA_ENABLED", None) os.environ.pop("YOOKASSA_SHOP_ID", None)