Skip to content

Instantly share code, notes, and snippets.

@ProvoK
Last active March 10, 2018 14:57
Show Gist options
  • Save ProvoK/10101902b1f56be946a99d576cbb397f to your computer and use it in GitHub Desktop.
Save ProvoK/10101902b1f56be946a99d576cbb397f to your computer and use it in GitHub Desktop.
import pytest
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
engine = create_engine('DB_CONNECTION_URL')
Session = sessionmaker()
@pytest.fixture(scope='module')
def connection():
connection = engine.connect()
yield connection
connection.close()
@pytest.fixture(scope='function')
def session(connection):
transaction = connection.begin()
session = Session(bind=connection)
yield session
session.close()
transaction.rollback()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment