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 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..0ebf95e 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", + 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", ],