from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from meal_manager.models import Base
import pytest


@pytest.fixture
def db_session():
    engine = create_engine("sqlite:///:memory:")
    Base.metadata.create_all(bind=engine)  # Create tables
    TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

    # Provide a session and the engine
    db = TestingSessionLocal()
    try:
        yield db
    finally:
        db.close()
