emergence-mini-dilles/tests/conftest.py
Jeuners ddf9598518 Emergence-Mini: minimaler Klon von Emergence-World
4 Agenten, 14 Landmarks, 15 Tools, 240x240 Grid, SQLite-Persistenz.
Round-Robin Turn-Manager mit Reactive Triggern, Town-Hall-Voting
(70%-Threshold) mit Live-Constitution-Amendment.

- engine/: db, world, agents, needs, tools, reasoning, governance, turn
- web/: Canvas-basierte Live-View mit WebSocket-Stream
- server.py: FastAPI + WebSocket auf 127.0.0.1:8080
- tests/: 70 Unit + Integration Tests (pytest), alle gruen
- smoke_test.py: 50+ End-to-End-Checks
- README: Quickstart, Architektur, Security, Tests, Lizenz
- .gitignore: DB, Cache, Logs

Basiert auf https://github.com/EmergenceAI/Emergence-World
(Lizenz: CC-BY-NC-4.0, Research-only)
2026-06-15 01:07:38 +02:00

45 lines
1.4 KiB
Python

"""Shared pytest fixtures: temporary DB, FastAPI client, bootstrapped engine."""
import os
import sys
import shutil
import tempfile
import pytest
from pathlib import Path
# Make the project root importable
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
# Disable the background engine thread for all tests; tests trigger rounds manually.
os.environ["EMERGENCE_TEST_MODE"] = "1"
@pytest.fixture(scope="function")
def tmp_db(monkeypatch):
"""Redirect the DB to a fresh temp file for each test."""
tmpdir = tempfile.mkdtemp(prefix="emerge-test-")
db_path = Path(tmpdir) / "test.db"
# Import here so we can patch the module-level constant
from engine import db
monkeypatch.setattr(db, "DB_PATH", db_path)
# Re-seed
db.init_db()
from engine import world, agents as agents_mod, tools
# Force re-bootstrap by clearing the seeded flag
db.set_world_state("landmarks_seeded", False)
db.set_world_state("agents_seeded", False)
world.bootstrap()
agents_mod.bootstrap()
tools.bootstrap()
yield db_path
shutil.rmtree(tmpdir, ignore_errors=True)
@pytest.fixture(scope="function")
def client(tmp_db):
"""FastAPI TestClient bound to the temp DB."""
# Ensure the app's startup hooks are run
from server import app
from fastapi.testclient import TestClient
with TestClient(app) as c:
yield c