From cfffc9ac94435b3f91596672a2103196e6fa1333 Mon Sep 17 00:00:00 2001 From: Mathias Guijarro Date: Thu, 2 May 2024 17:59:27 +0200 Subject: [PATCH] fix issue #656: add 'modules' keyword arg to load Redis extension modules at startup --- pytest_redis/executor/process.py | 5 +++++ pytest_redis/factories/proc.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/pytest_redis/executor/process.py b/pytest_redis/executor/process.py index c76a0dd5..36969ed7 100644 --- a/pytest_redis/executor/process.py +++ b/pytest_redis/executor/process.py @@ -58,6 +58,7 @@ def __init__( syslog_enabled: bool = False, appendonly: str = "no", datadir: Optional[Path] = None, + modules: Optional[list[str]] = None, ) -> None: # pylint:disable=too-many-locals """Init method of a RedisExecutor. @@ -79,6 +80,7 @@ def __init__( to the system logger :param datadir: location where all the process files will be located :param appendonly: + :param modules: list of paths of Redis extension modules to load """ if not datadir: datadir = Path(gettempdir()) @@ -142,6 +144,9 @@ def __init__( else: command.extend([f"--save {save}"]) + if modules: + command.extend([f"--loadmodule {module_path}" for module_path in modules]) + super().__init__(command, host, port, timeout=startup_timeout) @classmethod diff --git a/pytest_redis/factories/proc.py b/pytest_redis/factories/proc.py index a608b6aa..cf912e20 100644 --- a/pytest_redis/factories/proc.py +++ b/pytest_redis/factories/proc.py @@ -38,6 +38,7 @@ def redis_proc( syslog: Optional[bool] = None, loglevel: Optional[str] = None, datadir: Optional[str] = None, + modules: Optional[list[str]] = None, ) -> Callable[[FixtureRequest, TempPathFactory], Generator[RedisExecutor, None, None]]: """Fixture factory for pytest-redis. @@ -62,6 +63,7 @@ def redis_proc( :param datadir: Path for redis data files, including the unix domain socket. If this is not configured, then a temporary directory is created and used instead. + :param modules: list of paths of Redis extension modules to load :returns: function which makes a redis process """ @@ -109,6 +111,7 @@ def redis_proc_fixture( password=password or config["password"], startup_timeout=60, datadir=redis_datadir, + modules=modules, ) with redis_executor: yield redis_executor