Registry / testing / pytest-pgsql

pytest-pgsql

JSON →
library1.1.2pypypi✓ verified 82d ago

A pytest plugin providing fixtures and helpers for integration testing with PostgreSQL databases. Version 1.1.2 supports creating temporary test databases, managing database sessions, and rolling back transactions. Release cadence is sporadic.

pip install pytest-pgsql
INSTALL
IMPORT
SIG · PYTEST-PGSQL
P
pytest-pgsql
testingpythonv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

PostgreSQLTestDB
from pytest_pgsql import PostgreSQLTestDB
from pytest_pgsql import pgsql
create_engine_fixture
from pytest_pgsql import create_engine_fixture
from pytest_pgsql import pgsql
database
from pytest_pgsql import database
from pytest_pgsql import pgsql

Use the `pgsql` fixture to get a connection to a temporary test database. The fixture creates a fresh database for each test.

def test_example(pgsql): conn = pgsql['conn'] cur = conn.cursor() cur.execute("SELECT 1") assert cur.fetchone()[0] == 1
Debug
Known issues
breakingProject renamed from `pytest-postgresql` to `pytest-pgsql` in v1.0.0. Old package will be unpinned.
fix
Update your requirements to `pytest-pgsql` and change imports from `pytest_postgresql` to `pytest_pgsql`.
affects: <1.0.0
gotchaThe `pgsql` fixture returns a dictionary with keys 'conn', 'cur', 'engine', etc. Accessing the fixture directly as a connection object will raise TypeError.
fix
Use `pgsql['conn']` to get the connection, not `pgsql` alone if you expect a connection object.
affects: all
deprecatedThe `pgsql_session` fixture is deprecated in favor of `pgsql` with `autouse=True` or using `pgsql_transaction` for transactional tests.
fix
Replace `pgsql_session` with `pgsql` and manage transactions explicitly or use `pgsql_transaction`.
affects: >=1.1.0
Upgrade
Version history
1.1.2latest on PyPI · released May 13, 2020
Audit
Dependencies
pytestrequiredRequired as a pytest plugin
psycopg2requiredDatabase adapter for PostgreSQL
sqlalchemyoptionalOptional for SQLAlchemy session fixtures
Agent activity
17 hits · last 30 days
node
16
Resources
pytest-pgsql — pip install pytest-pgsql · libregistry