"""テスト共通の fixture(ダミーデータのみ.臨床データは使わない)."""
import sqlite3
from collections.abc import Iterator
from pathlib import Path
import pytest
from tiasdata import catalog
@pytest.fixture(autouse=True)
def _isolate_config_env(monkeypatch: pytest.MonkeyPatch) -> None:
# 開発者の環境変数が混ざらないようにする(テストごとに必要なら設定する)
monkeypatch.delenv("TIASDATA_CONFIG", raising=False)
@pytest.fixture
def catalog_conn(tmp_path: Path) -> Iterator[sqlite3.Connection]:
"""マイグレーション適用済みの目録(tmp_path に作る)."""
conn = catalog.connect(tmp_path / "catalog.sqlite", create=True)
catalog.apply_migrations(conn, "catalog")
try:
yield conn
finally:
conn.close()
@pytest.fixture
def identity_conn(tmp_path: Path) -> Iterator[sqlite3.Connection]:
"""マイグレーション適用済みの対応表(tmp_path に作る)."""
conn = catalog.connect(tmp_path / "identity.sqlite", create=True)
catalog.apply_migrations(conn, "identity")
try:
yield conn
finally:
conn.close()