All checks were successful
hufs-notice-crawler-cicd / build_push_deploy (push) Successful in 8m35s
33 lines
793 B
Python
33 lines
793 B
Python
from collections.abc import Generator
|
|
|
|
import pytest
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session, sessionmaker
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.db import Base
|
|
|
|
|
|
@pytest.fixture()
|
|
def db_session() -> Generator[Session, None, None]:
|
|
engine = create_engine(
|
|
"sqlite://",
|
|
future=True,
|
|
connect_args={"check_same_thread": False},
|
|
poolclass=StaticPool,
|
|
)
|
|
Base.metadata.create_all(bind=engine)
|
|
TestingSessionLocal = sessionmaker(
|
|
bind=engine,
|
|
autoflush=False,
|
|
autocommit=False,
|
|
future=True,
|
|
expire_on_commit=False,
|
|
)
|
|
session = TestingSessionLocal()
|
|
try:
|
|
yield session
|
|
finally:
|
|
session.close()
|
|
Base.metadata.drop_all(bind=engine)
|