pytest-redis icon indicating copy to clipboard operation
pytest-redis copied to clipboard

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

Open rmweiss opened this issue 3 years ago • 1 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

rmweiss avatar Apr 08 '22 06:04 rmweiss

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.

dazza-codes avatar Oct 23 '22 18:10 dazza-codes

I have been using

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

sc68cal avatar Nov 02 '22 18:11 sc68cal

Oh.... https://docs.python.org/3/library/shutil.html#shutil.which could make a nice default fallback 🤔

fizyk avatar Nov 07 '22 16:11 fizyk