Postgresql Testing
Simple Postgres helpers for testing with Python - no docker, brew, apt, etc - uses postgresql-binaries. The interface is simple, but close enough to the metal that you can use it to eg. have a new database per testing thread/use a fresh database from a TEMPLATE or archive.
pip install 'postgresql-testing[15]'
Then to use with pytest, eg:
import postgresql_testing
@pytest.fixture(scope="session")
def db() -> Iterator[str]:
config = postgresql_testing.DatabaseConfig.default("testing-db")
postgresql_testing.initdb(config.directory, on_existing="use")
with postgresql_testing.serve(config):
postgresql_testing.ensure_user(config)
postgresql_testing.create_database(config, on_existing="replace")
yield config.dsn
There are various useful flags and things - the source code is short enough to just dive in.
You can spin up a fresh db for immediate testing with:
postgresql-testing-serve postgres://testing:@localhost:8421/my-db
Bundled for good measure is a local-first copy of explain.dalibo.com
Get your query plan by:
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) SELECT ...
Then copy and:
pbpaste | postgresql-testing-explain
There are a couple of helpers for creating/using template dbs and archives. I have some vague long term plan for some kind of "Docker layers for migrated databases" with clever caching (or not), but I'm not quite sure what it looks like yet.
Some benchmarking:
| number of tables | create from template | dump to archive | create from archive |
|---|---|---|---|
| 100 | 80ms | 80ms (0.2MB) | 150ms |
| 1000 | 500ms | 300ms (2MB) | 1100ms |
On macos using a ramdisk, it is slightly quicker:
| number of tables | create from template | dump to archive | create from archive |
|---|---|---|---|
| 100 | 70ms | 70ms | 120ms |
| 1000 | 350ms | 300ms | 1000ms |
See claims/advice from planet Go.
Metadata
Release files for postgresql-testing 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| postgresql_testing-0.0.9.tar.gz | 288.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| postgresql_testing-0.0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 577.8 kB
Release files / postgresql_testing-0.0.9.tar.gz
| Download URL | postgresql_testing-0.0.9.tar.gz |
|---|---|
| Size | 288.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ec30683c0b4d34a292a25a455b50ca852feab0b58ba3b4f1fc68da552b9c027
|
|
BLAKE2b-256 checksum How to use checksums |
7ce3db0c65ef32401ca6356948126e654547a1511e56b89f99443e82484daca1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / postgresql_testing-0.0.9-py3-none-any.whl
| Download URL | postgresql_testing-0.0.9-py3-none-any.whl |
|---|---|
| Size | 289.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b09da766d4c4affb6262d57a93ce7a2c512d41e47cf33eea96d9863319fae9f3
|
|
BLAKE2b-256 checksum How to use checksums |
1c4a2f6bdf4c9a81149d96fc8b9dab11f0b8f82b6d0c23b458de958c99e5d0e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for postgresql-testing 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.