Files
planer/backend/tests/conftest.py
2026-07-22 16:12:23 +02:00

67 lines
2.1 KiB
Python

import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import config # noqa: E402
import database # noqa: E402
import fake_agents # noqa: E402
@pytest.fixture
async def testdb(tmp_path, monkeypatch):
"""Frische SQLite-Datei je Test; setzt die modul-globale Connection zurück."""
monkeypatch.setattr(config, "DB_PATH", tmp_path / "test.db")
database._db = None
await database.init_db()
yield database
await database.close_db()
@pytest.fixture
async def gescanntes_repo(tmp_path, monkeypatch, testdb):
"""mini_repo als echtes git-Repo mit echtem .planer/ (Fake-Scan, echter HEAD-Hash) —
Grundlage für Viewer-/Drift-/Routen-Tests."""
import shutil
import subprocess
import fake_agents
import kanban
import repo as repo_mod
import scan_board
wurzel = tmp_path / "mini"
shutil.copytree(Path(__file__).parent / "fixtures" / "mini_repo", wurzel)
env = {"PATH": "/usr/bin:/bin", "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
"GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t", "HOME": str(wurzel)}
def git(*args):
subprocess.run(["git", "-C", str(wurzel), *args], check=True, capture_output=True, env=env)
git("init", "-b", "main")
git("add", "-A")
git("commit", "-m", "start")
welt = fake_agents.Welt()
fake_agents.set_welt(welt)
fake_agents.standard_antworten(welt)
monkeypatch.setenv("PLANER_FAKE_AGENTS", "1")
monkeypatch.setattr(kanban, "RETRY_BACKOFF", 0.05)
ergebnis = await scan_board.run_scan(wurzel, "mini", stand=repo_mod.head_hash(wurzel))
assert ergebnis["status"] == "ok", ergebnis
git("add", "-A")
git("commit", "-m", "artefakte")
yield wurzel, git
fake_agents.set_welt(None)
@pytest.fixture
def fake_welt(monkeypatch):
"""Frische Fake-Welt + PLANER_FAKE_AGENTS aktiv; Tests hängen Antworten/Störungen an."""
welt = fake_agents.Welt()
fake_agents.set_welt(welt)
monkeypatch.setenv("PLANER_FAKE_AGENTS", "1")
yield welt
fake_agents.set_welt(None)