Skip to content

Commit a16eae8

Browse files
Kumzycofin
andauthored
feat: add support for postgres17 (#51)
Co-authored-by: Cody Fincher <cody@litestar.dev>
1 parent f4f5ec6 commit a16eae8

File tree

5 files changed

+106
-7
lines changed

5 files changed

+106
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ It is designed to offer pre-configured testing setups for many different types a
3232

3333
`pytest-databases` currently utilizes `docker compose` (or the legacy `docker-compose`) commands to manage the startup and shutdown of each database service. The following databases are currently available:
3434

35-
- **Postgres**: Version 12, 13, 14, 15, and 16 are available
35+
- **Postgres**: Version 12, 13, 14, 15, 16 and 17 are available
3636
- **MySQL**: Version 5.6, 5.7 and 8 are available
3737
- **Oracle**: Version 18c XE and 23C Free are available
3838
- **SQL Server**: Version 2022 is available

docs/index.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ Installing ``pytest-databases`` is as easy as calling your favorite Python packa
2020
2121
python3 -m pip install pytest-databases
2222
23-
.. tab-item:: pipx
23+
.. tab-item:: uv
2424
:sync: key2
2525

26+
.. code-block:: bash
27+
:caption: Using `uv <https://docs.astral.sh/uv/>`_
28+
29+
uv add pytest-databases
30+
31+
.. tab-item:: pipx
32+
:sync: key3
33+
2634
.. code-block:: bash
2735
:caption: Using `pipx <https://pypa.github.io/pipx/>`_
2836

src/pytest_databases/docker/docker-compose.postgres.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ services:
3939
- "${POSTGRES16_PORT:-5427}:5432" # use a non-standard port here
4040
environment:
4141
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret}
42+
postgres17:
43+
networks:
44+
- default
45+
image: postgres:17
46+
ports:
47+
- "${POSTGRES17_PORT:-5428}:5432" # use a non-standard port here
48+
environment:
49+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret}
4250
networks:
4351
default:
4452
driver: bridge

src/pytest_databases/docker/postgres.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,19 @@ def postgres15_port() -> int:
9393
def postgres16_port() -> int:
9494
return 5427
9595

96+
@pytest.fixture(scope="session")
97+
def postgres17_port() -> int:
98+
return 5428
99+
96100

97101
@pytest.fixture(scope="session")
98102
def default_postgres_service_name() -> str:
99-
return "postgres16"
103+
return "postgres17"
100104

101105

102106
@pytest.fixture(scope="session")
103-
def postgres_port(postgres16_port: int) -> int:
104-
return postgres16_port
107+
def postgres_port(postgres17_port: int) -> int:
108+
return postgres17_port
105109

106110

107111
@pytest.fixture(scope="session")
@@ -249,6 +253,33 @@ def postgres16_service(
249253
return postgres_docker_services
250254

251255

256+
@pytest.fixture(autouse=False, scope="session")
257+
def postgres17_service(
258+
postgres_docker_services: DockerServiceRegistry,
259+
postgres_docker_compose_files: list[Path],
260+
postgres17_port: int,
261+
postgres_database: str,
262+
postgres_user: str,
263+
postgres_password: str,
264+
) -> Generator[DockerServiceRegistry, None, None]:
265+
os.environ["POSTGRES_PASSWORD"] = postgres_password
266+
os.environ["POSTGRES_USER"] = postgres_user
267+
os.environ["POSTGRES_DATABASE"] = postgres_database
268+
os.environ["POSTGRES17_PORT"] = str(postgres17_port)
269+
postgres_docker_services.start(
270+
"postgres17",
271+
docker_compose_files=postgres_docker_compose_files,
272+
timeout=45,
273+
pause=1,
274+
check=postgres_responsive,
275+
port=postgres17_port,
276+
database=postgres_database,
277+
user=postgres_user,
278+
password=postgres_password,
279+
)
280+
yield postgres_docker_services
281+
282+
252283
# alias to the latest
253284
@pytest.fixture(autouse=False, scope="session")
254285
def postgres_service(
@@ -298,6 +329,25 @@ def postgres_startup_connection(
298329
) as conn:
299330
yield conn
300331

332+
@pytest.fixture(autouse=False, scope="session")
333+
def postgres17_startup_connection(
334+
postgres17_service: DockerServiceRegistry,
335+
postgres_docker_ip: str,
336+
postgres17_port: int,
337+
postgres_database: str,
338+
postgres_user: str,
339+
postgres_password: str,
340+
) -> Generator[psycopg.Connection, None, None]:
341+
with psycopg.connect(
342+
_make_connection_string(
343+
host=postgres_docker_ip,
344+
port=postgres17_port,
345+
user=postgres_user,
346+
password=postgres_password,
347+
database=postgres_database,
348+
),
349+
) as conn:
350+
yield conn
301351

302352
@pytest.fixture(autouse=False, scope="session")
303353
def postgres16_startup_connection(

tests/docker/test_postgres.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def test_postgres_default_config(
2121
postgres_user: str,
2222
postgres_password: str,
2323
) -> None:
24-
assert default_postgres_service_name == "postgres16"
25-
assert postgres_port == 5427
24+
assert default_postgres_service_name == "postgres17"
25+
assert postgres_port == 5428
2626
assert postgres_database == "postgres"
2727
assert postgres_user == "postgres"
2828
assert postgres_password == "super-secret"
@@ -87,6 +87,16 @@ def test_postgres_16_config(
8787
assert postgres_user == "postgres"
8888
assert postgres_password == "super-secret"
8989

90+
def test_postgres_17_config(
91+
postgres17_port: int,
92+
postgres_database: str,
93+
postgres_user: str,
94+
postgres_password: str,
95+
) -> None:
96+
assert postgres17_port == 5428
97+
assert postgres_database == "postgres"
98+
assert postgres_user == "postgres"
99+
assert postgres_password == "super-secret"
90100

91101
def test_postgres_services(
92102
postgres_docker_ip: str,
@@ -195,6 +205,29 @@ def test_postgres_16_services(
195205
)
196206
assert ping
197207

208+
def test_postgres_17_services(
209+
postgres_docker_ip: str,
210+
postgres17_service: DockerServiceRegistry,
211+
postgres17_port: int,
212+
postgres_database: str,
213+
postgres_user: str,
214+
postgres_password: str,
215+
) -> None:
216+
ping = postgres_responsive(
217+
postgres_docker_ip,
218+
port=postgres17_port,
219+
database=postgres_database,
220+
user=postgres_user,
221+
password=postgres_password,
222+
)
223+
assert ping
224+
225+
def test_postgres_17_services_after_start(
226+
postgres17_startup_connection: psycopg.Connection,
227+
) -> None:
228+
postgres17_startup_connection.execute("CREATE TABLE if not exists simple_table as SELECT 1")
229+
result = postgres17_startup_connection.execute("select * from simple_table").fetchone()
230+
assert bool(result is not None and result[0] == 1)
198231

199232
def test_postgres_16_services_after_start(
200233
postgres16_startup_connection: psycopg.Connection,

0 commit comments

Comments
 (0)