You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: README.md
+40-9Lines changed: 40 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,28 @@
1
1
# pgsql-test
2
2
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.
`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.
4
17
5
18
## Features
6
19
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
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
160
177
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
162
184
163
185
```python
164
186
@pytest.fixture
@@ -184,6 +206,15 @@ def test_user_count(db):
184
206
assert result['count'] ==0# Only seeded data
185
207
```
186
208
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
+
187
218
## RLS Testing
188
219
189
220
Test Row Level Security policies by switching contexts:
0 commit comments