28 lines
778 B
Python
28 lines
778 B
Python
import sys
|
|
|
|
sys.path.append("..")
|
|
|
|
import pytest
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
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()
|