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 @@ -32,7 +32,7 @@ It is designed to offer pre-configured testing setups for many different types a

`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:

- **Postgres**: Version 12, 13, 14, 15, and 16 are available
- **Postgres**: Version 12, 13, 14, 15, 16 and 17 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
10 changes: 9 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ Installing ``pytest-databases`` is as easy as calling your favorite Python packa

python3 -m pip install pytest-databases

.. tab-item:: pipx
.. tab-item:: uv
:sync: key2

.. code-block:: bash
:caption: Using `uv <https://docs.astral.sh/uv/>`_

uv add pytest-databases

.. tab-item:: pipx
:sync: key3

.. code-block:: bash
:caption: Using `pipx <https://pypa.github.io/pipx/>`_

Expand Down
8 changes: 8 additions & 0 deletions src/pytest_databases/docker/docker-compose.postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ services:
- "${POSTGRES16_PORT:-5427}:5432" # use a non-standard port here
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret}
postgres17:
networks:
- default
image: postgres:17
ports:
- "${POSTGRES17_PORT:-5428}:5432" # use a non-standard port here
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret}
networks:
default:
driver: bridge
56 changes: 53 additions & 3 deletions src/pytest_databases/docker/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ def postgres15_port() -> int:
def postgres16_port() -> int:
return 5427

@pytest.fixture(scope="session")
def postgres17_port() -> int:
return 5428


@pytest.fixture(scope="session")
def default_postgres_service_name() -> str:
return "postgres16"
return "postgres17"


@pytest.fixture(scope="session")
def postgres_port(postgres16_port: int) -> int:
return postgres16_port
def postgres_port(postgres17_port: int) -> int:
return postgres17_port


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -249,6 +253,33 @@ def postgres16_service(
return postgres_docker_services


@pytest.fixture(autouse=False, scope="session")
def postgres17_service(
postgres_docker_services: DockerServiceRegistry,
postgres_docker_compose_files: list[Path],
postgres17_port: int,
postgres_database: str,
postgres_user: str,
postgres_password: str,
) -> Generator[DockerServiceRegistry, None, None]:
os.environ["POSTGRES_PASSWORD"] = postgres_password
os.environ["POSTGRES_USER"] = postgres_user
os.environ["POSTGRES_DATABASE"] = postgres_database
os.environ["POSTGRES17_PORT"] = str(postgres17_port)
postgres_docker_services.start(
"postgres17",
docker_compose_files=postgres_docker_compose_files,
timeout=45,
pause=1,
check=postgres_responsive,
port=postgres17_port,
database=postgres_database,
user=postgres_user,
password=postgres_password,
)
yield postgres_docker_services


# alias to the latest
@pytest.fixture(autouse=False, scope="session")
def postgres_service(
Expand Down Expand Up @@ -298,6 +329,25 @@ def postgres_startup_connection(
) as conn:
yield conn

@pytest.fixture(autouse=False, scope="session")
def postgres17_startup_connection(
postgres17_service: DockerServiceRegistry,
postgres_docker_ip: str,
postgres17_port: int,
postgres_database: str,
postgres_user: str,
postgres_password: str,
) -> Generator[psycopg.Connection, None, None]:
with psycopg.connect(
_make_connection_string(
host=postgres_docker_ip,
port=postgres17_port,
user=postgres_user,
password=postgres_password,
database=postgres_database,
),
) as conn:
yield conn

@pytest.fixture(autouse=False, scope="session")
def postgres16_startup_connection(
Expand Down
37 changes: 35 additions & 2 deletions tests/docker/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_postgres_default_config(
postgres_user: str,
postgres_password: str,
) -> None:
assert default_postgres_service_name == "postgres16"
assert postgres_port == 5427
assert default_postgres_service_name == "postgres17"
assert postgres_port == 5428
assert postgres_database == "postgres"
assert postgres_user == "postgres"
assert postgres_password == "super-secret"
Expand Down Expand Up @@ -87,6 +87,16 @@ def test_postgres_16_config(
assert postgres_user == "postgres"
assert postgres_password == "super-secret"

def test_postgres_17_config(
postgres17_port: int,
postgres_database: str,
postgres_user: str,
postgres_password: str,
) -> None:
assert postgres17_port == 5428
assert postgres_database == "postgres"
assert postgres_user == "postgres"
assert postgres_password == "super-secret"

def test_postgres_services(
postgres_docker_ip: str,
Expand Down Expand Up @@ -195,6 +205,29 @@ def test_postgres_16_services(
)
assert ping

def test_postgres_17_services(
postgres_docker_ip: str,
postgres17_service: DockerServiceRegistry,
postgres17_port: int,
postgres_database: str,
postgres_user: str,
postgres_password: str,
) -> None:
ping = postgres_responsive(
postgres_docker_ip,
port=postgres17_port,
database=postgres_database,
user=postgres_user,
password=postgres_password,
)
assert ping

def test_postgres_17_services_after_start(
postgres17_startup_connection: psycopg.Connection,
) -> None:
postgres17_startup_connection.execute("CREATE TABLE if not exists simple_table as SELECT 1")
result = postgres17_startup_connection.execute("select * from simple_table").fetchone()
assert bool(result is not None and result[0] == 1)

def test_postgres_16_services_after_start(
postgres16_startup_connection: psycopg.Connection,
Expand Down