pytest-postgresql is a package for managing PostgreSQL connections and test databases from pytest. It suits tests that verify data reaches PostgreSQL, where an in-memory database or mocking may not reproduce production database behavior. section 5.2.1
Use it to address common database-test problems:
- Connect tests to a PostgreSQL test database. section 5.2.1
- Create, clear, or modify tables as part of testing. section 5.2.1
- Avoid retaining records between repeated test runs without risking a development or production database. section 5.2.1
ACH record-count test
A parser test inserts ACH records into PostgreSQL, queries the ach_files table, and checks the count. A pytest fixture can truncate the table after each test so repeated runs remain isolated. section 5.2.1
