testing.postgresql
automatically setups a postgresql instance in a temporary directory, and destroys it after testing
What it is and what it does
testing.postgresql is a test fixture library that spawns isolated PostgreSQL instances in temporary directories for the duration of a test run, then cleans them up automatically. It wraps the PostgreSQL command-line tools (initdb and postgres) to create fresh databases on demand, eliminating the need to manage shared test databases or mock database connections.
The package provides two main patterns: direct instantiation via Postgresql() for simple per-test isolation, or PostgresqlFactory with caching to reuse an initialized database schema across multiple tests, reducing setup overhead. It integrates with standard unittest patterns and supports passing connection details to database drivers via url() or dsn() methods.
Use it for:
- Unit tests that need real PostgreSQL behavior without a shared test database.
- Integration tests that require schema fixtures and data isolation between test cases.
- CI/CD pipelines where PostgreSQL must be provisioned and torn down per test run.
- Development workflows testing database migrations or schema changes in isolation.
- Parameterized tests that each need a fresh database state without manual setup code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically creates and tears down temporary PostgreSQL instances for testing, handling setup and cleanup without manual intervention.
No. The package is abandoned (latest release 2016-02-04) and targets Python 2.6, 2.7, 3.2, 3.3, 3.4, 3.5—all end-of-life versions. Modern Python and PostgreSQL compatibility are untested. For new projects, consider actively maintained alternatives.
Install
testing-postgresql on PyPI
pip
pip install testing-postgresqluv
uv add testing-postgresqlpoetry
poetry add testing-postgresqlInstalling testing.postgresql
Before you install
Low install friction with a pure-Python wheel distribution. However, the package is abandoned as of 2016 with no updates since its latest release, and its last commit was in 2023. The codebase targets Python 2.6, 2.7, 3.2, 3.3, 3.4, 3.5, all of which are end-of-life; compatibility with modern Python versions is unverified.
License in practice
Licensed under Apache License 2.0, a permissive license that allows commercial and private use with minimal restrictions. No licensing barrier to adoption.
Quickstart
import testing.postgresql
with testing.postgresql.Postgresql() as postgresql:
# connect using postgresql.url() or postgresql.dsn()
# run tests
PostgreSQL server binaries (initdb, postgres) must be present in your PATH; the package does not bundle them.
Verify before relying
- Compatibility with Python versions beyond 3.5 is not documented.
- Whether the package works with modern PostgreSQL versions is unclear.
- Current state of the testing.common.database dependency introduced in 1.3.0.
- Whether pg8000 1.10 dependency remains compatible with current environments.
Package facts
| License | Apache License 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 3,844 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,479,309/month — #2,293 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: testing.postgresql-1.3.0-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
pytest-pgsqlA pytest plugin that provides fixtures for…
permissive · top 15,000 on PyPI
testgrestestgres orchestrates temporary PostgreSQL…
unclear · top 15,000 on PyPI
testing.common.databaseProvides base classes and utilities for…
permissive · top 5,000 on PyPI
PyPgConfigPyPgConfig detects and exposes PostgreSQL…
permissive · top 15,000 on PyPI
py-pglitepy-pglite provides a zero-config PostgreSQL…
permissive · top 15,000 on PyPI
testcontainers-postgresProvides a PostgreSQL Docker container wrapper…
unclear · top 15,000 on PyPI
pytest-postgresqlA pytest plugin that provides fixtures to…
copyleft · top 5,000 on PyPI
psycopg2-poolManages a pool of reusable PostgreSQL…
copyleft · top 15,000 on PyPI
pytest-databasesProvides pytest fixtures that spin up isolated…
permissive · top 15,000 on PyPI
pgcopypgcopy wraps PostgreSQL's binary COPY protocol…
permissive · top 15,000 on PyPI