liveBook · Manning

Pytest-postgresql

As explained in Build Financial Software with Generative AI (From Scratch)

pytest-postgresql is a package that manages PostgreSQL connections and test databases for pytest.

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

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Defines the package's role and testing rationale but defers package-specific setup and API details.
Examples
Uses an ACH parser, the ach_files table, repeated record-count tests, and fixture-based table truncation.
What it assumes
Assumes pytest fixtures and database testing concepts while contrasting in-memory databases and mocking.
What you can do after
Apply it to isolate PostgreSQL-backed pytest tests while checking persisted records against the real database behavior.
How it connects
Connects pytest fixtures, PostgreSQL, in-memory databases, SQLite, H2, and mocking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.