From 9ddd538cc8d2faa542bdce257aacd85f1e3fe1e3 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 23 Sep 2025 13:29:56 +0200 Subject: [PATCH 1/4] feat: add postgres-18:rc1 as database and default postgres version --- docs/supported-databases/postgres.rst | 13 +++++---- src/pytest_databases/_service.py | 2 +- src/pytest_databases/docker/postgres.py | 38 ++++++++++++++++++++++++- tests/test_postgres.py | 2 ++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/docs/supported-databases/postgres.rst b/docs/supported-databases/postgres.rst index 701c128..b049ce2 100644 --- a/docs/supported-databases/postgres.rst +++ b/docs/supported-databases/postgres.rst @@ -8,7 +8,7 @@ Installation .. code-block:: bash - pip install pytest-databases[postgres] + pip install pytest-databases[postgres] Usage Example ------------- @@ -54,6 +54,7 @@ The following version-specific fixtures are also available: * ``postgres_15_image``, ``postgres_15_service``, ``postgres_15_connection``: PostgreSQL 15.x * ``postgres_16_image``, ``postgres_16_service``, ``postgres_16_connection``: PostgreSQL 16.x * ``postgres_17_image``, ``postgres_17_service``, ``postgres_17_connection``: PostgreSQL 17.x +* ``postgres_18_image``, ``postgres_18_service``, ``postgres_18_connection``: PostgreSQL 18.x * ``pgvector_image``, ``pgvector_service``. ``pgvector_connection``: Latest Available pgvector Docker image. Configuration @@ -67,13 +68,13 @@ Example usage with custom host: .. code-block:: bash - export POSTGRES_HOST="192.168.1.100" - pytest + export POSTGRES_HOST="192.168.1.100" + pytest Service API ----------- .. automodule:: pytest_databases.docker.postgres - :members: - :undoc-members: - :show-inheritance: + :members: + :undoc-members: + :show-inheritance: diff --git a/src/pytest_databases/_service.py b/src/pytest_databases/_service.py index 4a2c604..a9fbc42 100644 --- a/src/pytest_databases/_service.py +++ b/src/pytest_databases/_service.py @@ -10,10 +10,10 @@ import filelock import pytest +from docker import DockerClient from docker.errors import APIError, ImageNotFound from typing_extensions import Self -from docker import DockerClient from pytest_databases.helpers import get_xdist_worker_id from pytest_databases.types import ServiceContainer diff --git a/src/pytest_databases/docker/postgres.py b/src/pytest_databases/docker/postgres.py index cf40b44..a166473 100644 --- a/src/pytest_databases/docker/postgres.py +++ b/src/pytest_databases/docker/postgres.py @@ -244,6 +244,26 @@ def postgres_17_service( yield service +@pytest.fixture(autouse=False, scope="session") +def postgres_18_service( + docker_service: DockerService, + xdist_postgres_isolation_level: XdistIsolationLevel, + postgres_host: str, + postgres_user: str, + postgres_password: str, +) -> Generator[PostgresService, None, None]: + with _provide_postgres_service( + docker_service, + image="postgres:18-rc1", + name="postgres-18", + xdist_postgres_isolate=xdist_postgres_isolation_level, + host=postgres_host, + user=postgres_user, + password=postgres_password, + ) as service: + yield service + + @pytest.fixture(autouse=False, scope="session") def postgres_11_connection( postgres_11_service: PostgresService, @@ -356,9 +376,25 @@ def postgres_17_connection( yield conn +@pytest.fixture(autouse=False, scope="session") +def postgres_18_connection( + postgres_18_service: PostgresService, +) -> Generator[psycopg.Connection, None, None]: + with psycopg.connect( + _make_connection_string( + host=postgres_18_service.host, + port=postgres_18_service.port, + user=postgres_18_service.user, + password=postgres_18_service.password, + database=postgres_18_service.database, + ), + ) as conn: + yield conn + + @pytest.fixture(autouse=False, scope="session") def postgres_image() -> str: - return "postgres:17" + return "postgres:18" @pytest.fixture(autouse=False, scope="session") diff --git a/tests/test_postgres.py b/tests/test_postgres.py index 05ee400..5c2f7de 100644 --- a/tests/test_postgres.py +++ b/tests/test_postgres.py @@ -13,6 +13,7 @@ "postgres_15_service", "postgres_16_service", "postgres_17_service", + "postgres_18_service", "alloydb_omni_service", "pgvector_service", ], @@ -57,6 +58,7 @@ def test({service_fixture}) -> None: "postgres_15_connection", "postgres_16_connection", "postgres_17_connection", + "postgres_18_connection", "alloydb_omni_connection", "pgvector_connection", ], From 8d458e982d7ce4035afdf58c6a502ef6976b5f64 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 23 Sep 2025 13:31:56 +0200 Subject: [PATCH 2/4] chore: add version 18 to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20dfab3..a5bad8e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Ready-made database fixtures for your pytest tests. `pytest-databases` uses the Docker Python SDK to manage the startup and shutdown of database services in containers. The following databases are currently available: -- **Postgres**: Version 12, 13, 14, 15, 16 and 17 are available +- **Postgres**: Version 12, 13, 14, 15, 16, 17 and 18 are available - **MySQL**: Version 5.6, 5.7 and 8 are available - **Oracle**: Version 18c XE and 23C Free are available - **SQL Server**: Version 2022 is available From 3e9948741df44649941bacb547f8478eb3032615 Mon Sep 17 00:00:00 2001 From: Julien Date: Tue, 23 Sep 2025 13:42:37 +0200 Subject: [PATCH 3/4] fix: correct postgres 18rc1 image name --- src/pytest_databases/docker/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_databases/docker/postgres.py b/src/pytest_databases/docker/postgres.py index a166473..aff9eec 100644 --- a/src/pytest_databases/docker/postgres.py +++ b/src/pytest_databases/docker/postgres.py @@ -254,7 +254,7 @@ def postgres_18_service( ) -> Generator[PostgresService, None, None]: with _provide_postgres_service( docker_service, - image="postgres:18-rc1", + image="postgres:18rc1", name="postgres-18", xdist_postgres_isolate=xdist_postgres_isolation_level, host=postgres_host, From ab253cfa164877decc231f3aaa401f575138b2c6 Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 25 Sep 2025 19:43:39 +0200 Subject: [PATCH 4/4] feat: official release of postgres18 --- src/pytest_databases/docker/postgres.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_databases/docker/postgres.py b/src/pytest_databases/docker/postgres.py index aff9eec..0ebf95e 100644 --- a/src/pytest_databases/docker/postgres.py +++ b/src/pytest_databases/docker/postgres.py @@ -254,7 +254,7 @@ def postgres_18_service( ) -> Generator[PostgresService, None, None]: with _provide_postgres_service( docker_service, - image="postgres:18rc1", + image="postgres:18", name="postgres-18", xdist_postgres_isolate=xdist_postgres_isolation_level, host=postgres_host,