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.

https://travis-ci.org/tk0miya/testing.postgresql.svg?branch=master https://coveralls.io/repos/tk0miya/testing.postgresql/badge.png?branch=master https://codeclimate.com/github/tk0miya/testing.postgresql/badges/gpa.svg
Documentation

https://github.com/tk0miya/testing.postgresql

Issues

https://github.com/tk0miya/testing.postgresql/issues

Download

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

Install

Use pip:

$ pip 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 postgres 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

  • pg8000 1.10

License

Apache License 2.0

History

1.2.0 (2015-05-17)

  • Use pg8000 for connector to create test database

  • Connect to postgres to create test database (instead of template1)

1.1.2 (2015-04-06)

  • Fix bugs:

    • Do not call os.getpid() on destructor (if not needed)

    • Raise detailed RuntimeError if initdb exits non-zero

1.1.1 (2015-01-18)

  • Disable logging_collector feature (For Fedora)

  • Fix bugs:

    • MacPorts default path is /opt/local/lib/postgresql*, no dash

1.1.0 (2014-12-20)

  • Invoke ‘postgres’ command instead of ‘postmaster’

1.0.6 (2014-07-19)

  • Fix #1 Dirty postmaster shut down

1.0.5 (2014-07-19)

  • Fix path for PostgreSQL

  • Use absolute path for which command

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.2.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

testing.postgresql-1.2.0-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for testing.postgresql-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4fa559d3671b73fd1cf0e68f304468cc8394a5fbf2be5416d10bbd20df37c374
MD5 71c3d582c708d19d5a4ceb9f987629d6
BLAKE2b-256 49207866887ca1fd478ea1de8e91ab557e9865b6cc97a9e94773007a1b50fce9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for testing.postgresql-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d5997ef3680133b4584ac42095b72bf7a94ae9f7261061ad095958e99daa65f8
MD5 868805a5f9c6a6db7119f37793700515
BLAKE2b-256 1b54df9a512ec43a36183b269a7e3d3f72d56b5bba758defbf36f66bbdba6b7b

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