import sys import pytest from sqlalchemy import create_engine sys.path.append("..") from src.database import Base as ProductionBase from tests.config.database import (SQLALCHEMY_DATABASE_URL, TestBase, TestSessionLocal) @pytest.fixture(scope="function") def db_session(): engine = create_engine(SQLALCHEMY_DATABASE_URL) print(SQLALCHEMY_DATABASE_URL) ProductionBase.metadata.create_all(bind=engine) TestBase.metadata.create_all(bind=engine) session = TestSessionLocal(bind=engine) try: yield session finally: session.rollback() TestBase.metadata.drop_all(bind=engine) ProductionBase.metadata.drop_all(bind=engine) session.close()