In Memory DB Fixture

PHOTO EMBED

Wed Jul 13 2022 10:40:32 GMT+0000 (Coordinated Universal Time)

Saved by @ClemensBerteld

import testing.postgresql
from sqlalchemy import create_engine

@pytest.fixture
def create_local_db():
    with testing.postgresql.Postgresql() as postgresql:
        engine = create_engine(postgresql.url())
        yield engine


def test_example(create_local_db):
    engine = create_local_db
    with engine.connect() as conn:
        res = [*conn.execute(f'SELECT 1;')]
        assert res[0][0] == 1
content_copyCOPY