← Files Dispensa: lista de comprasARCHIVED FILE

tests/conftest.py

585 Bytes · Nov 19, 2026 · 00:38 UTC

↓ Download file

See the change to this file →

import pytest
from sqlalchemy import create_engine, event
from sqlalchemy.pool import StaticPool

from mcp_despensa_hub.db import SCHEMA, Base


def sqlite_engine():
    engine = create_engine(
        "sqlite://",
        connect_args={"check_same_thread": False},
        poolclass=StaticPool,
    )

    @event.listens_for(engine, "connect")
    def attach_schema(dbapi_conn, _connection_record):
        dbapi_conn.execute(f"ATTACH DATABASE ':memory:' AS {SCHEMA}")

    Base.metadata.create_all(engine)
    return engine


@pytest.fixture
def engine():
    return sqlite_engine()

SHA-256: 823835a0b308295bc1b0393c9f11dae40c08b99144d2fa91e60a2bd536ca3e31