Skip to content

Commit cf7b9fe

Browse files
authored
feat: Add support for PostgreSQL 18 (#98)
1 parent f5e23c9 commit cf7b9fe

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Ready-made database fixtures for your pytest tests.
2626

2727
`pytest-databases` uses the Docker Python SDK to manage the startup and shutdown of database services in containers. The following databases are currently available:
2828

29-
- **Postgres**: Version 12, 13, 14, 15, 16 and 17 are available
29+
- **Postgres**: Version 12, 13, 14, 15, 16, 17 and 18 are available
3030
- **MySQL**: Version 5.6, 5.7 and 8 are available
3131
- **Oracle**: Version 18c XE and 23C Free are available
3232
- **SQL Server**: Version 2022 is available

docs/supported-databases/postgres.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Installation
88

99
.. code-block:: bash
1010
11-
pip install pytest-databases[postgres]
11+
pip install pytest-databases[postgres]
1212
1313
Usage Example
1414
-------------
@@ -54,6 +54,7 @@ The following version-specific fixtures are also available:
5454
* ``postgres_15_image``, ``postgres_15_service``, ``postgres_15_connection``: PostgreSQL 15.x
5555
* ``postgres_16_image``, ``postgres_16_service``, ``postgres_16_connection``: PostgreSQL 16.x
5656
* ``postgres_17_image``, ``postgres_17_service``, ``postgres_17_connection``: PostgreSQL 17.x
57+
* ``postgres_18_image``, ``postgres_18_service``, ``postgres_18_connection``: PostgreSQL 18.x
5758
* ``pgvector_image``, ``pgvector_service``. ``pgvector_connection``: Latest Available pgvector Docker image.
5859

5960
Configuration
@@ -67,13 +68,13 @@ Example usage with custom host:
6768

6869
.. code-block:: bash
6970
70-
export POSTGRES_HOST="192.168.1.100"
71-
pytest
71+
export POSTGRES_HOST="192.168.1.100"
72+
pytest
7273
7374
Service API
7475
-----------
7576

7677
.. automodule:: pytest_databases.docker.postgres
77-
:members:
78-
:undoc-members:
79-
:show-inheritance:
78+
:members:
79+
:undoc-members:
80+
:show-inheritance:

src/pytest_databases/_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import filelock
1212
import pytest
13+
from docker import DockerClient
1314
from docker.errors import APIError, ImageNotFound
1415
from typing_extensions import Self
1516

16-
from docker import DockerClient
1717
from pytest_databases.helpers import get_xdist_worker_id
1818
from pytest_databases.types import ServiceContainer
1919

src/pytest_databases/docker/postgres.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ def postgres_17_service(
244244
yield service
245245

246246

247+
@pytest.fixture(autouse=False, scope="session")
248+
def postgres_18_service(
249+
docker_service: DockerService,
250+
xdist_postgres_isolation_level: XdistIsolationLevel,
251+
postgres_host: str,
252+
postgres_user: str,
253+
postgres_password: str,
254+
) -> Generator[PostgresService, None, None]:
255+
with _provide_postgres_service(
256+
docker_service,
257+
image="postgres:18",
258+
name="postgres-18",
259+
xdist_postgres_isolate=xdist_postgres_isolation_level,
260+
host=postgres_host,
261+
user=postgres_user,
262+
password=postgres_password,
263+
) as service:
264+
yield service
265+
266+
247267
@pytest.fixture(autouse=False, scope="session")
248268
def postgres_11_connection(
249269
postgres_11_service: PostgresService,
@@ -356,9 +376,25 @@ def postgres_17_connection(
356376
yield conn
357377

358378

379+
@pytest.fixture(autouse=False, scope="session")
380+
def postgres_18_connection(
381+
postgres_18_service: PostgresService,
382+
) -> Generator[psycopg.Connection, None, None]:
383+
with psycopg.connect(
384+
_make_connection_string(
385+
host=postgres_18_service.host,
386+
port=postgres_18_service.port,
387+
user=postgres_18_service.user,
388+
password=postgres_18_service.password,
389+
database=postgres_18_service.database,
390+
),
391+
) as conn:
392+
yield conn
393+
394+
359395
@pytest.fixture(autouse=False, scope="session")
360396
def postgres_image() -> str:
361-
return "postgres:17"
397+
return "postgres:18"
362398

363399

364400
@pytest.fixture(autouse=False, scope="session")

tests/test_postgres.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"postgres_15_service",
1414
"postgres_16_service",
1515
"postgres_17_service",
16+
"postgres_18_service",
1617
"alloydb_omni_service",
1718
"pgvector_service",
1819
],
@@ -57,6 +58,7 @@ def test({service_fixture}) -> None:
5758
"postgres_15_connection",
5859
"postgres_16_connection",
5960
"postgres_17_connection",
61+
"postgres_18_connection",
6062
"alloydb_omni_connection",
6163
"pgvector_connection",
6264
],

0 commit comments

Comments
 (0)