import pytest from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import StaticPool from app.database import Base from app.models import BaseUnit, Product from app.seed import ensure_builtin_units @pytest.fixture() def db(): engine = create_engine( "sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool, ) Base.metadata.create_all(bind=engine) TestingSession = sessionmaker(bind=engine, autoflush=False, autocommit=False) session = TestingSession() ensure_builtin_units(session) # Einheiten (Gramm, Kilogramm, …) für Umrechnung try: yield session finally: session.close() engine.dispose() @pytest.fixture() def rice(db): """Produkt mit Basiseinheit Gramm und 500 g pro Packung.""" product = Product( name="Basmati-Reis", base_unit=BaseUnit.gram, package_size=500, source="manual" ) db.add(product) db.commit() db.refresh(product) return product