Re: RFC: adding pytest as a supported test framework

Jelte Fennema-Nio <postgres@jeltef.nl>

From: "Jelte Fennema-Nio" <postgres@jeltef.nl>
To: "Jacob Champion" <jacob.champion@enterprisedb.com>
Cc: "PostgreSQL Hackers" <pgsql-hackers@postgresql.org>, "Robert Haas" <robertmhaas@gmail.com>, "Daniel Gustafsson" <daniel@yesql.se>, "Andres Freund" <andres@anarazel.de>, "Tom Lane" <tgl@sss.pgh.pa.us>, "Peter Eisentraut" <peter@eisentraut.org>, "Nazir Bilal Yavuz" <byavuz81@gmail.com>
Date: 2025-10-22T12:44:15Z
Lists: pgsql-hackers

Attachments

On Mon, 22 Sept 2025 at 22:30, Jacob Champion <jacob.champion@enterprisedb.com> wrote:
> Done this way in v2-0002

Okay I finally managed to do some testing of this patchset while working
on a patchset of mine where I'm adding a GoAway message to the protocol
(should be ready to be published soon)

First of all: THANK YOU! It's a great base to start from and I hope we
can relatively soon have something merged, that we can gradually
improve.

I had some problems using it for my own tests though. The primary
reasons for that were:
1. It was missing functionality to send queries and get results.
2. A lot of the fixtures I wanted to use were located in the ssl tests
   directory instead of the shared fixtures module.
3. When running pytest manually I had to configure LD_LIBRARY_PATH

So here's your patchset with an additional commit on top that does a
bunch of refactoring/renaming and adding features. I hope you like it. I
tried to make the most common actions easy to do.

The primary features it adds are:
- A `sql` method on `PGconn`: It takes a query and returns the results
    as native python types.
- A `conn` fixture: Which is a libpq based connection to the default
    Postgres server.
- Use the `pg_config` binary to find the libdir and bindir (can be
    overridden by setting PG_CONFIG). Otherwise I had to use
    LD_LIBRARY_PATH when running pytest manually.

The refactoring it does:
- Rename `pg_server` fixture to `pg` since it'll likely be one of the
    most commonly used ones.
- Rename `pg` module to `pypg` to avoid naming conflict/shadowing
    problems with the newly renamed `pg` fixture
- Move class definitions outside of fixtures to separate modules (either
    in the `pypg` module or the new `libpq` module)
- Move all "general" fixtures to the `pypg.fixtures` module, instead of
    having them be defined in the ssl module.