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.

Source Distribution

ephemeral-postgres-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file ephemeral-postgres-0.2.0.tar.gz.

File metadata

  • Download URL: ephemeral-postgres-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for ephemeral-postgres-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f58ff8d108b346d63f48b4fceeaa3f6cf834a4afd2c6418077b6d55f125ceefc
MD5 3729943860c1246246e8798a2d8d5d88
BLAKE2b-256 b40d206bed161abc97b1fbce9a71f958dcf6dd872adb34f71cc9200ad178915f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page