skillfed

testgres

Testing utility for PostgreSQL and its extensions

testgres v1.15.2 101.2K downloads/30d#12,953 on PyPI157
License unclear PostgreSQL Active released

What it is and what it does

testgres is a test utility that spins up isolated, temporary PostgreSQL clusters for use in Python test suites. It handles the full lifecycle—initialization, startup, query execution, and cleanup—so tests can focus on logic rather than database provisioning. The package wraps PostgreSQL command-line tools (initdb, pg_ctl, psql) and provides Python bindings for common operations like executing queries, managing transactions, creating backups, spawning replicas, and running pgbench benchmarks.

It integrates with pytest via fixtures and the standard Python logging module, making it straightforward to aggregate logs from multiple test nodes. The package supports both local and remote (Linux-only) node provisioning via SSH, and provides sensible configuration defaults that can be customized. With six runtime dependencies (pg8000, port-for, six, psutil, packaging, and testgres.os_ops) and low install friction, it is designed to be dropped into existing test suites with minimal setup overhead.

Use it for:

  • Run integration tests against a fresh PostgreSQL instance that is created, used, and destroyed within a single test function or fixture.
  • Test PostgreSQL extensions or custom configurations by provisioning nodes with specific postgresql.conf settings via default_conf() and append_conf().
  • Verify replication and backup workflows by creating a master node, taking backups, spawning replicas, and asserting catchup behavior.
  • Execute quick performance benchmarks using pgbench through testgres in a controlled, repeatable test environment.
  • Parallelize test suites across multiple isolated PostgreSQL nodes using pytest-xdist, with each node on a distinct port.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

testgres orchestrates temporary PostgreSQL clusters for Python tests, handling initialization, startup, query execution, and automatic cleanup.

Yes, if you need to test PostgreSQL-dependent code in isolation. The package is actively maintained, has no known vulnerabilities, and low install friction. The main caveat is the unclear PostgreSQL license treatment—verify it aligns with your project's licensing before committing. The blocker is a working PostgreSQL installation; if you already have one, testgres is a straightforward way to automate cluster provisioning in tests.

Install

testgres on PyPI

pip

pip install testgres

uv

uv add testgres

poetry

poetry add testgres

Installing testgres

Before you install

Low install friction with a pure-Python wheel and six runtime dependencies. Active maintenance with a release 10 days ago and commits through August 2026; the project has 157 stars and no known vulnerabilities.

License in practice

Licensed under PostgreSQL (license_treatment: unclear). The PostgreSQL license is permissive but differs from common open-source licenses; verify compatibility with your project's licensing requirements before adopting.

Quickstart

pip install testgres

import testgres

with testgres.get_new_node() as node:
    node.init()
    node.start()
    result = node.execute('select 1')
    print(result)

Requires PostgreSQL binaries (initdb, pg_ctl, psql) in PATH or accessible via PG_CONFIG or PG_BIN environment variable; supports Python 3.7.3 and newer.

Verify before relying

  • Whether the PostgreSQL license (license_treatment: unclear) is compatible with your project's licensing model.
  • Performance characteristics when running many parallel test nodes (documentation mentions pytest-xdist but does not quantify overhead).

Package facts

License PostgreSQL (unclear)
Python support supports the current Python release (>=3.7.3)
Install friction low — pure-Python wheel
Runtime dependencies 6 — pg8000, port-for, six, psutil, packaging, testgres.os_ops
Maintenance actively maintained — 10 days since the last release
Last repo commit
First released
Downloads 101,216/month — #12,953 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: testgres-1.15.2-py3-none-any.whl

Keywords: test, testing, postgresql

Intended Audience :: DevelopersOperating System :: UnixProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: Testing

Tags

postgresql test cluster setuptemporary postgres database testingpytest postgresql fixturespostgres node orchestrationtest database provisioningpostgresql integration testingephemeral postgres instances
postgres-testingtest-fixturesdatabase-provisioning

More Libraries packages