Registry / testing / testgres

testgres

JSON →
library1.13.7pypypi✓ verified 34d ago

testgres is a testing utility for PostgreSQL and its extensions, providing a simple API to manage temporary PostgreSQL instances, create databases, execute queries, and test replication. Current version 1.13.7, PyPI release with monthly cadence.

testingdatabase
Install & Compatibility
Where this runs
tested against v1.14.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.390s · 22.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.372s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Direct import of the module; no submodule import needed.

import testgres

Quickstart demonstrating starting a temporary PostgreSQL node, initializing, starting, creating a database, and executing a query.

import testgres def test_postgres(): # Start a temporary PostgreSQL instance with testgres.get_new_node('test_node') as node: node.init() node.start() # Create a database and execute a query db = node.execute('CREATE DATABASE testdb') result = node.execute('SELECT 1') print(result) # Node is automatically stopped and cleaned up
Debug
Known footguns
gotchatestgres.get_new_node() requires a node name that is unique per test session. Reusing names across tests may cause conflicts.
gotchaThe temporary PostgreSQL instance uses a port assigned by the OS. If multiple tests run concurrently, port collisions can occur. Use the 'port' parameter to specify a range or fixed port.
deprecatedThe `execute()` method returns a list of tuples by default; in older versions it returned a string. If you rely on string output, update your code.
gotchatestgres nodes do not automatically clean up the data directory if the context manager exits due to an exception. Use explicit cleanup or catch exceptions.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
26 hits · last 30 days
petalbot
7
gptbot
4
ahrefsbot
4
amazonbot
4
claudebot
3
script
1
Resources