pytest-pgsql
Pytest plugins and helpers for tests using a Postgres database.
Decision gist · record as of 2026-08-14
Yes, with conditions. The package is stable and production-ready for projects that need isolated PostgreSQL test databases. However, adopt it only if you can accept that maintenance is minimal—the last release was 2020-05-13, and there is no active development roadmap. Verify compatibility with your PostgreSQL version and Python version before committing, and monitor the repository for any breaking changes in dependencies like testing.postgresql.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a PostgreSQL server accessible to the test environment; testing.postgresql (a runtime dependency) handles temporary instance setup but still needs PostgreSQL binaries available on the system.
- Low install friction with a pure-Python wheel.
- However, the package is aging—last release was 2020-05-13 and the last commit 2025-08-20, suggesting minimal active maintenance despite the repository not being archived.
License · maintenance · safety
permissive license (permissive) — Licensed under a permissive BSD license (Copyright Clover Health, Inc.), which imposes no significant restrictions on use or redistribution in most contexts.
last release 2020-05-13 (2284 days) · last repo commit 2025-08-20 · 69 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 85,357 downloads/mo, #13,928 on PyPI
Alternatives
Verify before relying
pip install pytest-pgsql
import pytest
from pytest_pgsql import postgresql_db
def test_example(postgresql_db):
postgresql_db.session.execute('CREATE TABLE test (id INT)')
postgresql_db.session.commit()- Whether the package works reliably with modern PostgreSQL versions beyond those released around 2020.
- Compatibility with Python versions beyond 3.6 (classifiers only list up to 3.6, but requires_python is unspecified).
- Current state of the testing.postgresql dependency and whether it remains actively maintained.
What it is and what it does
pytest-pgsql is a pytest plugin that automates database fixture management for tests that need PostgreSQL. It provides two main fixtures—postgresql_db and transacted_postgresql_db—each exposing a SQLAlchemy session and either an engine or connection object. The plugin automatically creates a fresh temporary database for each test and cleans it up afterward, ensuring test isolation without manual teardown.
The package integrates freezegun for time manipulation within tests, allowing you to freeze and advance time in both Python and the database. It also provides utility methods for common test setup tasks: loading CSV files into tables, executing SQL scripts with variable binding, managing PostgreSQL extensions, and creating schemas and tables from SQLAlchemy definitions. Both fixtures rely on testing.postgresql to handle temporary instance provisioning.
Use it for
- Unit testing ORM code that requires a real database without manual setup or teardown between tests.
- Testing time-dependent database logic by freezing and advancing time within test blocks.
- Loading test data from CSV files or SQL scripts into a clean database for each test run.
- Testing PostgreSQL extension availability and installation within test fixtures.
- Verifying schema and table creation logic in database migration or initialization code.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, with conditions.
The package is stable and production-ready for projects that need isolated PostgreSQL test databases. However, adopt it only if you can accept that maintenance is minimal—the last release was 2020-05-13, and there is no active development roadmap. Verify compatibility with your PostgreSQL version and Python version before committing, and monitor the repository for any breaking changes in dependencies like testing.postgresql.
Install
pytest-pgsql on PyPI
Before you install
Low install friction with a pure-Python wheel. However, the package is aging—last release was 2020-05-13 and the last commit 2025-08-20, suggesting minimal active maintenance despite the repository not being archived.
Requires a PostgreSQL server accessible to the test environment; testing.postgresql (a runtime dependency) handles temporary instance setup but still needs PostgreSQL binaries available on the system.
License in practice
Licensed under a permissive BSD license (Copyright Clover Health, Inc.), which imposes no significant restrictions on use or redistribution in most contexts.
Quickstart
pip install pytest-pgsql
import pytest
from pytest_pgsql import postgresql_db
def test_example(postgresql_db):
postgresql_db.session.execute('CREATE TABLE test (id INT)')
postgresql_db.session.commit()
Verify before relying
- Whether the package works reliably with modern PostgreSQL versions beyond those released around 2020.
- Compatibility with Python versions beyond 3.6 (classifiers only list up to 3.6, but requires_python is unspecified).
- Current state of the testing.postgresql dependency and whether it remains actively maintained.
Package facts
| License | permissive license permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 4 packagesfreezegunpytestsqlalchemytesting.postgresql |
| Maintenance | Aging 2,284 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 85,357 / month, #13,928 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: DatabaseTopic :: Software Development :: Testing |
Evidence: pytest_pgsql-1.1.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “temporary postgres database testing”
- pytest-pgsqlA pytest plugin that provides fixtures for running tests against…
- testing.postgresqlAutomatically creates and tears down temporary PostgreSQL instances…
- testgrestestgres orchestrates temporary PostgreSQL clusters for Python tests,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also testing.postgresql · pytest-databases · pgsanity · py-pglite · testgres · pytest-postgresql · pytest-freezer · pytest-mock-resources · pytest-datadir · pytest-freezegun