Skip to content

Commit f10a8d9

Browse files
committed
docs: Add Constructive header, badges, and improve per-test rollback docs
- Add centered Constructive logo matching other packages - Add CI badge and MIT license badge - Update features list to match pgsql-test (TS) style - Rename 'Transaction Isolation' to 'Per-Test Rollback' with expanded docs - Add 'How It Works' and 'Why This Matters' sections explaining rollback
1 parent 0238950 commit f10a8d9

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
# pgsql-test
22

3-
PostgreSQL testing framework for Python - instant, isolated databases with automatic transaction rollback. The Python companion to [pgsql-test](https://github.com/launchql/pgsql-test) for TypeScript/Node.js.
3+
<p align="center" width="100%">
4+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/constructive-io/pgsql-test-python/actions/workflows/test.yml">
9+
<img height="20" src="https://github.com/constructive-io/pgsql-test-python/actions/workflows/test.yml/badge.svg" />
10+
</a>
11+
<a href="https://github.com/constructive-io/pgsql-test-python/blob/main/LICENSE">
12+
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13+
</a>
14+
</p>
15+
16+
`pgsql-test` gives you instant, isolated PostgreSQL databases for each test — with automatic transaction rollbacks, context switching, and clean seeding. The Python companion to [pgsql-test](https://github.com/launchql/pgsql-test) for TypeScript/Node.js.
417

518
## Features
619

7-
- **Instant isolated databases**: Each test gets a fresh database with a unique UUID name
8-
- **Transaction rollback**: Changes are automatically rolled back after each test
9-
- **pgpm integration**: Run database migrations using [pgpm](https://github.com/pgpm-io/pgpm) (PostgreSQL Package Manager)
10-
- **Composable seeding**: Seed your database with SQL files, custom functions, pgpm modules, or combine multiple strategies
11-
- **RLS testing support**: Easy context switching for testing Row Level Security policies
12-
- **Clean API**: Simple, intuitive interface inspired by the Node.js pgsql-test library
20+
* **Instant test DBs** — each one seeded, isolated, and UUID-named
21+
* **Per-test rollback** — every test runs in its own transaction with savepoint-based rollback via `before_each()`/`after_each()`
22+
* **RLS-friendly** — test with role-based auth via `set_context()`
23+
* **pgpm integration** — run database migrations using [pgpm](https://github.com/pgpm-io/pgpm) (PostgreSQL Package Manager)
24+
* **Flexible seeding** — run `.sql` files, programmatic seeds, pgpm modules, or combine multiple strategies
25+
* **Auto teardown** — no residue, no reboots, just clean exits
1326

1427
## Installation
1528

@@ -156,9 +169,18 @@ def test_with_seeding(seeded_db):
156169
assert len(users) > 0
157170
```
158171

159-
## Transaction Isolation
172+
## Per-Test Rollback
173+
174+
The `before_each()` and `after_each()` methods provide automatic transaction rollback for each test. This ensures complete isolation between tests - any changes made during a test are automatically rolled back, so each test starts with a clean slate.
175+
176+
### How It Works
160177

161-
Use `before_each()` and `after_each()` for per-test isolation:
178+
1. `before_each()` begins a transaction and creates a savepoint
179+
2. Your test runs and makes changes to the database
180+
3. `after_each()` rolls back to the savepoint, undoing all changes
181+
4. The next test starts fresh with only the seeded data
182+
183+
### Basic Pattern
162184

163185
```python
164186
@pytest.fixture
@@ -184,6 +206,15 @@ def test_user_count(db):
184206
assert result['count'] == 0 # Only seeded data
185207
```
186208

209+
### Why This Matters
210+
211+
Without per-test rollback, tests can interfere with each other:
212+
- Test A inserts a user
213+
- Test B expects 0 users but finds 1
214+
- Tests become order-dependent and flaky
215+
216+
With `before_each()`/`after_each()`, each test is completely isolated, making your test suite reliable and deterministic.
217+
187218
## RLS Testing
188219

189220
Test Row Level Security policies by switching contexts:

0 commit comments

Comments
 (0)