48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""Shared test fixtures.
|
|
|
|
Infrastructure integration tests are gated on env vars:
|
|
- TREX_POSTGRESQL_TEST_DSN : PostgreSQL repository/outbox/migration tests
|
|
- TREX_RABBITMQ_TEST_URL : RabbitMQ transport + intent RPC E2E tests
|
|
- TREX_KIS_BROKER_* : KIS sandbox round-trip test
|
|
|
|
When a gate is unset the corresponding tests are skipped; unit tests
|
|
(in-memory adapters, stub transport) always run.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
_PG_TABLES = (
|
|
"killswitch_exclusion",
|
|
"snapshot_pause",
|
|
"ledger_outbox",
|
|
"intent_log",
|
|
"slot_transition_log",
|
|
"daily_symbol_entries",
|
|
"daily_slot",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def pg_dsn() -> str:
|
|
dsn = os.environ.get("TREX_POSTGRESQL_TEST_DSN")
|
|
if not dsn:
|
|
pytest.skip("TREX_POSTGRESQL_TEST_DSN not set; skipping PostgreSQL integration test")
|
|
return dsn
|
|
|
|
|
|
@pytest.fixture
|
|
def pg_clean(pg_dsn: str):
|
|
"""Apply migrations and truncate slot-core tables before each PG test."""
|
|
import psycopg
|
|
|
|
from trex_core.adapters.persistence.migrate import apply_migrations
|
|
|
|
apply_migrations(pg_dsn)
|
|
with psycopg.connect(pg_dsn, autocommit=True) as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute(f"TRUNCATE {', '.join(_PG_TABLES)}")
|
|
return pg_dsn
|