Skip to main content

Redis fixtures and fixture factories for Pytest.

Project description

https://raw.githubusercontent.com/ClearcodeHQ/pytest-redis/master/logo.png

pytest-redis

Latest PyPI version Wheel Status Supported Python Versions License

Package status

Tests Coverage Status

What is this?

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.

How to use

Plugin contains three fixtures

  • redisdb - it’s a client fixture that has functional scope. After each test, it cleans Redis database for more reliable tests.

  • redis_proc - session scoped fixture, that starts Redis instance at it’s first use and stops at the end of the tests.

  • redis_nooproc - a nooprocess fixture, that’s connecting to already running redis

Simply include one of these fixtures into your tests fixture list.

You can also create additional redis client and process fixtures if you’d need to:

from pytest_redis import factories

redis_my_proc = factories.redis_proc(port=None, logsdir='/tmp')
redis_my = factories.redisdb('redis_my_proc')

Connecting to already existing redis database

Some projects are using already running redis servers (ie on docker instances). In order to connect to them, one would be using the redis_nooproc fixture.

redis_external = factories.redisdb('redis_nooproc')

By default the redis_nooproc fixture would connect to postgresql instance using 6379 port. Standard configuration options apply to it.

These are the configuration options that are working on all levels with the redis_nooproc fixture:

Configuration

You can define your settings in three ways, it’s fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:

  • Fixture factory argument

  • Command line option

  • Configuration option in your pytest.ini file

Configuration options

Redis server option

Fixture factory argument

Command line option

pytest.ini option

Noop process fixture

Default

executable

executable

–redis-exec

redis_exec

/usr/bin/redis-server

host

host

–redis-host

redis_host

host

127.0.0.1

port

port

–redis-port

redis_port

port

random

connection timeout

timeout

–redis-timeout

redis_timeout

30

number of databases

db_count

–redis-db-count

redis_db_count

8

Whether to enable logging to the system logger

syslog

–redis-syslog

redis_syslog

False

Log directory location

logsdir

–redis-logsdir

redis_logsdir

$TMPDIR

Redis log verbosity level

loglevel

–redis-loglevel

redis_loglevel

notice

Compress dump files

compress

–redis-compress

redis_compress

True

Add checksum to RDB files

checksum

–redis-rdbcompress

redis_rdbchecksum

False

Save configuration

save

–redis-save

redis_save

“”

Example usage:

  • pass it as an argument in your own fixture

    redis_proc = factories.redis_proc(port=8888)
  • use --redis-port command line option when you run your tests

    py.test tests --redis-port=8888
  • specify your port as redis_port in your pytest.ini file.

    To do so, put a line like the following under the [pytest] section of your pytest.ini:

    [pytest]
    redis_port = 8888

Options below are for configuring redis client fixture.

Redis client option

Fixture factory argument

Command line option

pytest.ini option

Default

decode_response

decode

–redis-decode

redis_decode

False

Package resources

CHANGELOG

2.0.0

  • [feature] ability to properly connect to already existing postgresql server using redis_nooproc fixture.

  • [enhancement] dropped support for python 2.7

1.3.2

  • [bugfix] - close file descriptor when reading redis version (by brunsgaard)

1.3.1

  • [bugfix] do not run redis explicitly with shell=True

1.3.0

  • [enhancement] RedisExecutor now provides attribute with path to unixsocket

  • [enhancement] redis client fixture now connects to redis through unixsocket by default

  • [enhancement] Version check got moved to executor, to be run just before starting Redis Server

  • [feature] ability to configure decode_responses for redis client in command line, pytest.ini or factory argument.

  • [bugfix] set decode_responses to False, same as StrictRedis default

  • [enhancement] ability to change decode_responses value

1.2.1

  • [bugfix] raise specific error in case the redis executable path has been misconfigured or does not exists

1.2.0

  • [feature] ability to configure syslog-enabled for redis in command line, pytest.ini or factory argument.

  • [feature] ability to configure rdbchecksum for redis in command line, pytest.ini or factory argument.

  • [feature] ability to configure rdbcompression for redis in command line, pytest.ini or factory argument.

  • [ehnacement] - RedisExecutor handling parameters and their translation to redis values if needed.

  • [feature] ability to configure save option for redis in command line, pytest.ini or factory argument.

1.1.1

  • [cleanup] removed path.py dependency

1.1.0

  • [feature] - migrate usage of getfuncargvalue to getfixturevalue. require at least pytest 3.0.0

1.0.0

  • [enhancements] removed the possibility to pass the custom config. No need to include one in package now.

  • [enhancements] command line, pytest.ini and fixture factory options for setting custom number of databases in redis

  • [enhancements] command line, pytest.ini and fixture factory options for redis log verbosity

  • [enhancements] command line, pytest.ini and fixture factory options for modifying connection timeout

  • [enhancements] command line and pytest.ini options for modifying executable

  • [enhancements] command line and pytest.ini options for modifying host

  • [enhancements] command line and pytest.ini options for modifying port

  • [enhancements] command line and pytest.ini options for modifying logs directory destination

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytest_redis-2.0.0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_redis-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_redis-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for pytest_redis-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 725041832a679d0fe190b7d789505b26a3ae8edcc5dc6ab1aafb1bdce8265c5f
MD5 f6497a677dd5866d55d6de59efa81650
BLAKE2b-256 22625dead98f45111b9f54419ffdffe0cacccecf3eca9c9840e9ed666d01c0c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page