GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Table Of Contents
  • testgres package
  • Show Source

This view

  • Original page
  • New address

GeezerVison is showing postgrespro.github.io — Testgres documentation — testgres 1.5 documentation

Testgres documentation¶

Testgres is a PostgreSQL testing framework.

Installation¶

To install testgres, run:

pip install testgres

We encourage you to use virtualenv for your testing environment.

Usage¶

Environment¶

Note: by default testgres runs initdb, pg_ctl, psql provided by PATH.

There are several ways to specify a custom postgres installation:

  • export PG_CONFIG environment variable pointing to the pg_config executable;
  • export PG_BIN environment variable pointing to the directory with executable files.

Example:

export PG_BIN=$HOME/pg_10/bin
python my_tests.py

Examples¶

Here is an example of what you can do with testgres:

# create a node with random name, port, etc
with testgres.get_new_node() as node:

    # run inidb
    node.init()

    # start PostgreSQL
    node.start()

    # execute a query in a default DB
    print(node.execute('select 1'))

# ... node stops and its files are about to be removed

Backup & replication¶

It’s quite easy to create a backup and start a new replica:

with testgres.get_new_node('master') as master:
    master.init().start()

    # create a backup
    with master.backup() as backup:

        # create and start a new replica
        replica = backup.spawn_replica('replica').start()

        # catch up with master node
        replica.catchup()

        # execute a dummy query
        print(replica.execute('postgres', 'select 1'))

Modules¶

  • testgres package
    • testgres.api
    • testgres.backup
    • testgres.config
    • testgres.connection
    • testgres.enums
    • testgres.exceptions
    • testgres.node
    • testgres.pubsub
©2016-2018, Postgres Professional. | Powered by Sphinx 1.7.5 & Alabaster 0.7.11 | Page source
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.