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.
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 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
psycopg2 2.5
License
Apache License 2.0
History
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file testing.postgresql-1.1.2.tar.gz
.
File metadata
- Download URL: testing.postgresql-1.1.2.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a7645f45532bd4c891aeaddec053187e02c473b7afa7ae31b1bcceb828e735e |
|
MD5 | 084607d3b93f26cbdfb73ff29f2d673e |
|
BLAKE2b-256 | 0622364eb8b969a98df84a38f8dfcf362035706ed1871e01c4622281dd2abb79 |
File details
Details for the file testing.postgresql-1.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: testing.postgresql-1.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9095b98ffa100ca7b9ec514a272624d8c160703dd65746a6b0324e47cc6ef6b |
|
MD5 | efd25577b19f05bfe4457b1830666586 |
|
BLAKE2b-256 | e6d6f1a996e50b043df6c24493f1aee7a6315c5191f075d12b95597a7383eb06 |