Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions docs/supported-databases/postgres.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Installation

.. code-block:: bash

pip install pytest-databases[postgres]
pip install pytest-databases[postgres]

Usage Example
-------------
Expand Down Expand Up @@ -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
Expand All @@ -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:
2 changes: 1 addition & 1 deletion src/pytest_databases/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 37 additions & 1 deletion src/pytest_databases/docker/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"postgres_15_service",
"postgres_16_service",
"postgres_17_service",
"postgres_18_service",
"alloydb_omni_service",
"pgvector_service",
],
Expand Down Expand Up @@ -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",
],
Expand Down
Loading