Skip to main content

Start an ephemeral postgres instance for easy testing

Project description

ephemeral-postgres

Build Status

ephemeral-postgres is a python package for easily setting up, testing, and finally tearing down postgres instances. It can be easily integrated in most test suites but has been primarily used with pytest.

Installation

pip install ephemeral-postgres

Example

import ephemeral_postgres
import psycopg2

with ephemeral_postgres.postgres() as uri:
    con = psycopg2.connect(uri)
    cur = con.cursor()
    cur.execute('select * from pg_database')
    for row in cur.fetchall():
        print(row)

Alternatively, if you would like to run an external Postgres server, you can override ephemeral_postgres from starting a new instance by setting the environment variable EPHEMERAL_POSTGRES_URI accordingly. For example:

export EPHEMERAL_POSTGRES_URI="postgresql://postgres:postgres@localhost:5432/postgres"
python "import ephemeral_postgres; print(ephemeral_postgres.postgres()[0])"

Developing

pip install -e .[test]

# run unit tests
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ephemeral-postgres, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size ephemeral-postgres-0.2.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page