26 lines
578 B
Python
26 lines
578 B
Python
|
|
import pytest
|
||
|
|
from sqlalchemy import create_engine
|
||
|
|
from sqlalchemy.orm import sessionmaker
|
||
|
|
|
||
|
|
from web.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def engine():
|
||
|
|
eng = create_engine("sqlite:///:memory:", echo=False)
|
||
|
|
Base.metadata.create_all(eng)
|
||
|
|
yield eng
|
||
|
|
Base.metadata.drop_all(eng)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def db_session(engine):
|
||
|
|
connection = engine.connect()
|
||
|
|
transaction = connection.begin()
|
||
|
|
Session = sessionmaker(bind=connection)
|
||
|
|
session = Session()
|
||
|
|
yield session
|
||
|
|
session.close()
|
||
|
|
transaction.rollback()
|
||
|
|
connection.close()
|