Skip to main content

automatically setups a postgresql instance in a temporary directory, and destroys it after testing

Project description

About

testing.postgresql automatically setups a postgresql instance in a temporary directory, and destroys it after testing.

drone.io CI build status Latest PyPI version Number of PyPI downloads
Documentation

https://bitbucket.org/tk0miya/testing.postgresql/src/default/README.rst

Issues

https://bitbucket.org/tk0miya/testing.postgresql/issues

Download

https://pypi.python.org/pypi/testing.postgresql

Install

Use easy_install (or pip):

$ easy_install testing.postgresql

And testing.postgresql requires PostgreSQL server in your PATH.

Usage

Create PostgreSQL instance using testing.postgresql.Postgresql:

import testing.postgresql
from sqlalchemy import create_engine

# Lanuch new PostgreSQL server
with testing.postgresql.Postgresql() as postgresql:
    # connect to PostgreSQL
    engine = create_engine(postgresql.url())

    # if you use postgresql or other drivers:
    #   import psycopg2
    #   db = psycopg2.connect(**postgresql.dsn())

    #
    # do any tests using PostgreSQL...
    #

# PostgreSQL server is terminated here

testing.postgresql.Postgresql executes initdb and postmaster on instantiation. On deleting Postgresql object, it terminates PostgreSQL instance and removes temporary directory.

If you want a database including tables and any fixtures for your apps, use copy_data_from keyword:

# uses a copy of specified data directory of PostgreSQL.
postgresql = testing.postgresql.Postgresql(copy_data_from='/path/to/your/database')

For example, you can setup new PostgreSQL server for each testcases on setUp() method:

import unittest
import testing.postgresql

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.postgresql = testing.postgresql.Postgresql()

    def tearDown(self):
        self.postgresql.stop()

Requirements

  • Python 2.6, 2.7, 3.2, 3.3, 3.4

  • psycopg2

License

Apache License 2.0

History

1.0.4 (2014-06-19)

  • Fix timeout on terminating postgresql

  • Support PostgreSQL on /usr/local/bin (cf. FreeBSD ports)

  • Fix bugs

1.0.3 (2014-06-11)

  • Fix ImportError if caught SIGINT on py3

1.0.2 (2013-12-06)

  • Change behavior: Postgresql#stop() cleans workdir

  • Fix caught AttributeError on object deletion

1.0.1 (2013-12-05)

  • Add @skipIfNotInstalled decorator (alias of skipIfNotFound)

  • Suport python 2.6 and 3.2

1.0.0 (2013-12-04)

  • Add @skipIfNotFound decorator

0.1.0 (2013-11-26)

  • First release

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

testing.postgresql-1.0.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

testing.postgresql-1.0.4-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file testing.postgresql-1.0.4.tar.gz.

File metadata

File hashes

Hashes for testing.postgresql-1.0.4.tar.gz
Algorithm Hash digest
SHA256 f034ac8d8b5f6df8813c5f10442413aff47d1a46ed37920a724c8a547a0f5a16
MD5 4fa845bf2ec41a1de399bb264ef38e3a
BLAKE2b-256 0e3b63a9d4505f8600621a4775b5b19dbbca67755103ceac08937e31f07a4c24

See more details on using hashes here.

File details

Details for the file testing.postgresql-1.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for testing.postgresql-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b1260d7abea713b016ee01f2f331fa65062faf5166b16c69e45199a436d13b6
MD5 18ea5d25de12d5b6a5ac98058bd5bfc4
BLAKE2b-256 29f287aa196f8d874fa5c3ffcbb41d507e3227863caa5f9d4e216798a74a2001

See more details on using hashes here.

Supported by

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