Postgresql fixtures and fixture factories for Pytest.
Project description
pytest-postgresql
Package status
What is this?
This is a pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database. It allows you to specify fixtures for PostgreSQL process and client.
How to use
Plugin contains two fixtures
postgresql - it’s a client fixture that has functional scope. After each test it ends all leftover connections, and drops test database from PostgreSQL ensuring repeatability.
postgresql_proc - session scoped fixture, that starts PostgreSQL instance at it’s first use and stops at the end of the tests.
Simply include one of these fixtures into your tests fixture list.
You can also create additional postgresql client and process fixtures if you’d need to:
from pytest_postgresql import factories
postgresql_my_proc = factories.postgresql_proc(
port=None, logsdir='/tmp')
postgresql_my = factories.postgresql('postgresql_my_proc')
Configuration
You can define your settings in three ways, it’s fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:
Fixture factory argument
Command line option
Configuration option in your pytest.ini file
PostgreSQL option |
Fixture factory argument |
Command line option |
pytest.ini option |
Default |
---|---|---|---|---|
Path to executable |
executable |
–postgresql-exec |
postgresql_exec |
/usr/lib/postgresql/9.1/bin/pg_ctl |
host |
host |
–postgresql-host |
postgresql_host |
127.0.0.1 |
port |
port |
–postgresql-port |
postgresql_port |
random |
postgresql user |
user |
–postgresql-user |
postgresql_user |
postgres |
Starting parameters |
startparams |
–postgresql-startparams |
postgresql_startparams |
-w |
Log directory location |
logsdir |
–postgresql-logsdir |
postgresql_logsdir |
$TMPDIR |
Log filename’s prefix |
logsprefix |
–postgresql-logsprefix |
postgresql_logsprefix |
|
Location for unixsockets |
unixsocket |
–postgresql-unixsocketdir |
postgresql_unixsocketdir |
$TMPDIR |
Example usage:
pass it as an argument in your own fixture
postgresql_proc = factories.postgresql_proc( port=8888)
use --postgresql-port command line option when you run your tests
py.test tests --postgresql-port=8888
specify your port as postgresql_port in your pytest.ini file.
To do so, put a line like the following under the [pytest] section of your pytest.ini:
[pytest] postgresql_port = 8888
Package resources
CHANGELOG
1.2.0
[bugfix] - disallow connection to database before it gets dropped.
[cleanup] - removed path.py dependency
1.1.1
[bugfix] - Fixing the default pg_ctl path creation
1.1.0
[feature] - migrate usage of getfuncargvalue to getfixturevalue. require at least pytest 3.0.0
1.0.0
create command line and pytest.ini configuration options for postgresql starting parameters
create command line and pytest.ini configuration options for postgresql username
make the port random by default
create command line and pytest.ini configuration options for executable
create command line and pytest.ini configuration options for host
create command line and pytest.ini configuration options for port
Extracted code from pytest-dbfixtures
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 pytest-postgresql-1.2.0.tar.gz
.
File metadata
- Download URL: pytest-postgresql-1.2.0.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29a985c10b51ae4ed0df64258656d167269c9ca93c12747e0a8f4f543f67be75 |
|
MD5 | 3c862208744b4eb709197ef8b95c67da |
|
BLAKE2b-256 | d6e1e83afca3dffc471c2259f24b75a063885ee2c2612217b0004a78cc468b34 |
File details
Details for the file pytest_postgresql-1.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_postgresql-1.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3fb4b0bda3ea7c52f377628b3bbf5c576acafd6d8a82255352ccb62911e6db |
|
MD5 | 941efe6930a9965d90b7be4252ebe610 |
|
BLAKE2b-256 | 8a25d0e7ca2ca99633b3138353c7caf53fa4754394603a0ec73308417fc18761 |