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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter