Skip to main content

Postgresql fixtures and fixture factories for Pytest.

Project description

pytest-postgresql

https://img.shields.io/pypi/v/pytest-postgresql.svg Wheel Status Supported Python Versions License

Package status

Tests Coverage Status Requirements 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 lefover connections, and drops test database from PostgreSQL ensuirng 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.postgreesql('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 directory 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.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


Download files

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

Source Distribution

pytest-postgresql-1.0.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

pytest_postgresql-1.0.0-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-postgresql-1.0.0.tar.gz.

File metadata

File hashes

Hashes for pytest-postgresql-1.0.0.tar.gz
Algorithm Hash digest
SHA256 046854bacf2313cf1fd9c8539f9b3979a0fcb73fe356312c90eab515f796aa98
MD5 b39d6d0e45880510c22401175e9f981f
BLAKE2b-256 adc6e09c743a0a897ece90a60eb2a8521627c7f38f2aacb647ae3dab836b584a

See more details on using hashes here.

File details

Details for the file pytest_postgresql-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_postgresql-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1a4bd8148610780582c4c16f7e668c95c65ce31d3ef6ff81f24d2aefdee77e6f
MD5 597aab161394fbabf50262921ad710a2
BLAKE2b-256 73f69132e5975415becf7dc131dfd8cb761d0eda00e3659ea4b6618234cc055c

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