Created
April 4, 2020 08:06
-
-
Save geoffkoh/d23e4c612e782af45ce828ebf2e8884f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard imports | |
import tempfile | |
# Third party imports | |
import pytest | |
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker | |
from pytest_postgresql import factories | |
# Using the factory to create a postgresql instance | |
socket_dir = tempfile.TemporaryDirectory() | |
postgresql_my_proc = factories.postgresql_proc( | |
port=None, unixsocketdir=socket_dir.name) | |
postgresql_my = factories.postgresql('postgresql_my_proc') | |
@pytest.fixture(scope='function') | |
def setup_database(postgresql_my): | |
def dbcreator(): | |
return postgresql_my.cursor().connection | |
engine = create_engine('postgresql+psycopg2://', creator=dbcreator) | |
Base.metadata.create_all(engine) | |
Session = sessionmaker(bind=engine) | |
session = Session() | |
yield session | |
session.close() | |
# end setup_database() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment