Valkey#
Integration with Valkey using the Valkey Docker Image.
Installation#
pip install pytest-databases valkey
The valkey extra no longer installs the valkey client. Readiness is verified over a Python stdlib TCP socket using the RESP protocol, so install your own client alongside pytest-databases.
Usage Example#
from valkey import Valkey
from pytest_databases.docker.valkey import ValkeyService
pytest_plugins = ["pytest_databases.docker.valkey"]
def test(valkey_service: ValkeyService) -> None:
client = Valkey(
host=valkey_service.host,
port=valkey_service.port,
db=valkey_service.db,
)
client.set("test_key", "test_value")
assert client.get("test_key") == b"test_value"
Available Fixtures#
valkey_port: The port number for the Valkey service.valkey_host: The host name for the Valkey service.valkey_image: The Docker image to use for Valkey.valkey_service: A fixture that provides aValkeyService(host,port,container,db).xdist_valkey_isolation_level:database(default) orserver.
Under pytest-xdist with database isolation, workers share one container and each worker uses its own
logical database (ValkeyService.db). Every 16 workers get an additional shared container. With server
isolation every worker gets its own container.
Service API#
Valkey container service fixtures.
- class pytest_databases.docker.valkey.ValkeyService(container: docker.models.containers.Container, host: str, port: int, db: int)[source]#
Bases:
ServiceContainerConnection metadata for a running Valkey container service.
- pytest_databases.docker.valkey.provide_valkey_service(docker_service: DockerService, image: str, isolation_level: XdistIsolationLevel) Generator[ValkeyService, None, None][source]#
Start and yield a Valkey service container.
- Parameters:
docker_service – Docker service manager.
image – Container image name.
isolation_level – xdist isolation mode.
- Yields:
A configured
ValkeyServiceinstance.
- pytest_databases.docker.valkey.valkey_host(valkey_service: ValkeyService) str[source]#
Return the reachable host address for the Valkey service.
- pytest_databases.docker.valkey.valkey_image() str[source]#
Return the container image tag for Valkey.
- pytest_databases.docker.valkey.valkey_port(valkey_service: ValkeyService) int[source]#
Return the bound host port for the Valkey service.
- pytest_databases.docker.valkey.valkey_responsive(service_container: ServiceContainer) bool[source]#
Check whether a Valkey service responds to a RESP PING command.
Deprecated in v0.20.0 and removed in v1.0.0. Use
pytest_databases.docker.redis.redis_responsive()instead.- Parameters:
service_container – Running service container metadata.
- Returns:
True when the endpoint replies with
PONG, otherwise False.