Skip to main content

postgresql-integration-test

Overview

postgresql-integration-test is a python module that creates a temporary PostgreSQL instance to use for testing your application. You will need a working PostgreSQL install. It does not have to be running, the binaries are needed.

Download and Install

To install use pip:

$ pip install postgresql-integration-test

Or clone the repo:

$ git clone https://github.com/jasondcamp/postgresql-integration-test.git

Configuration

Class arguments

The following class arguments can be overridden by passing them in, these arguments will override the config file arguments.

Argument Description Default
username Username for database root
host Host to bind 127.0.0.1
port Port to bind random
postgres_binary Location of postgres binary Searches paths
timeout_start Timeout to start PostgreSQL 30 seconds
timeout_stop Timeout to stop PostgreSQL 30 seconds
log_level Log level INFO
config_file Configuration file postgresql-integration-test.cfg

postgresql-integration-test config file

Default settings can be overridden in a config file. The default name is postgresql-integration-test.cfg in the local directory and can be overridden by passing in the config option to the instance creation.

Example config

database:
  host: '127.0.0.1'
  port: '9999'
  username: 'root'
  postgresql_binary: '/usr/sbin/postgres'

general:
  log_level: 'DEBUG'
  timeout_start: 30
  timeout_stop: 30

Usage

import

from postgresql_integration_test import PostgreSQL

run

Starts up the postgresql server

postgresql = PostgreSQL()
instance = postgresql.run()

stop

Stops the postgres server

postgresql.stop()

Example Code

#!/usr/bin/env python3

from postgresql_integration_test import PostgreSQL
import psycopg2

postgres = PostgreSQL(config='/some/dir/postgresql-integration-test.cfg')
instance = postgres.run()

# Make query to database
cnx = psycopg2.connect(
    user=instance.username,
    host=instance.host,
    port=instance.port,
    database="test",
)
cursor = cnx.cursor()
cursor.execute("SELECT id FROM some_table")
for _result in cursor:
    result = _result
cursor.close()
cnx.close()

postgres.stop()

Download files

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

Source Distribution

postgresql_integration_test-0.0.7.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postgresql_integration_test-0.0.7-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file postgresql_integration_test-0.0.7.tar.gz.

File metadata

File hashes

Hashes for postgresql_integration_test-0.0.7.tar.gz
Algorithm Hash digest
SHA256 22b8e85a4741efb10429e2d7f9efb0c98582a68cc101f5bba60d050ba02dfa18
MD5 37a2e0a6d51c8122da26d27d1e1ca614
BLAKE2b-256 ec4c4859f535a5a442248dc2543afe10bccdc0ad971c3b90b0db43f785dfbf4c

See more details on using hashes here.

File details

Details for the file postgresql_integration_test-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for postgresql_integration_test-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1eb0bbd89e5b2a0c2f23289e2e5e5a02c902407026f47ce6063600e249bc0226
MD5 1bc528cba7361e6c0c350634dc02ad58
BLAKE2b-256 faff273b7e30abb02b0b24178c80604959fe97baf9facde3f73e6d786174a077

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page