ClearcodeHQ / pytest-redis

Redis fixtures and fixture factories for Pytest.This is a pytest plugin, that enables you to test your code that relies on a running Redis database. It allows you to specify additional fixtures for Redis process and client.

Home Page:https://pypi.python.org/pypi/pytest-redis/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Find redis-server binary in other locations than /usr/bin

rmweiss opened this issue · comments

What action do you want to perform

Use shutil.which to detect the location of the redis-server binary instead of using the currently hard-coded "/usr/bin/redis-server".

Maybe with a fallback to "/usr/bin/redis-server" if which doesn't find anything.

Something like:

[...]
from shutil import which
[...]
parser.addini(
    name="redis_exec",
    help=_help_exec, 
    default=which("redis-server") or "/usr/bin/redis-server"
)

What are the results

What are the expected results

Tried to provide redis using docker run -d redis, with no joy, and then found this issue.

On OSX, brew installs

$ which redis-server
/usr/local/bin/redis-server

The proposed solution could resolve an exception like:

    def _check_version(self):
        """Check redises version if it's compatible."""
        with os.popen(f"{self.executable} --version") as version_output:
            version_string = version_output.read()
        if not version_string:
            raise RedisMisconfigured(
>               f"Bad path to redis_exec is given:"
                f" {self.executable} not exists or wrong program"
            )
E           pytest_redis.executor.RedisMisconfigured: Bad path to redis_exec is given: /usr/bin/redis-server not exists or wrong program

/opt/conda/envs/aio-aws/lib/python3.7/site-packages/pytest_redis/executor.py:228: RedisMisconfigured

Another proposal is to make the redisdb fixture a lot smarter about how it connects to any redis, to cover all the bases for the common defaults.

I have been using

redis_my_proc = factories.redis_proc(port=6379, executable=shutil.which('redis-server'))