{"id":25658322,"url":"https://github.com/dbfixtures/pytest-redis","last_synced_at":"2026-03-11T03:02:46.541Z","repository":{"id":13775042,"uuid":"74789605","full_name":"dbfixtures/pytest-redis","owner":"dbfixtures","description":"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.","archived":false,"fork":false,"pushed_at":"2026-03-03T20:53:23.000Z","size":1761,"stargazers_count":104,"open_issues_count":8,"forks_count":16,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-03-04T00:29:05.855Z","etag":null,"topics":["pytest","pytest-plugin","python","redis"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/pytest-redis/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbfixtures.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-11-25T21:39:29.000Z","updated_at":"2026-03-02T23:09:39.000Z","dependencies_parsed_at":"2023-09-22T16:15:07.325Z","dependency_job_id":"1d35fed6-bb0a-4872-a629-800378581901","html_url":"https://github.com/dbfixtures/pytest-redis","commit_stats":{"total_commits":522,"total_committers":17,"mean_commits":"30.705882352941178","dds":0.6724137931034483,"last_synced_commit":"d5348077a1751f7318a426c1348a550d7b497f14"},"previous_names":["dbfixtures/pytest-redis","clearcodehq/pytest-redis"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/dbfixtures/pytest-redis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbfixtures%2Fpytest-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbfixtures%2Fpytest-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbfixtures%2Fpytest-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbfixtures%2Fpytest-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbfixtures","download_url":"https://codeload.github.com/dbfixtures/pytest-redis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbfixtures%2Fpytest-redis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30368571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"online","status_checked_at":"2026-03-11T02:00:07.027Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytest","pytest-plugin","python","redis"],"created_at":"2025-02-24T00:05:40.212Z","updated_at":"2026-03-11T03:02:46.536Z","avatar_url":"https://github.com/dbfixtures.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: https://raw.githubusercontent.com/dbfixtures/pytest-redis/master/logo.png\n    :width: 100px\n    :height: 100px\n\npytest-redis\n============\n\n.. image:: https://img.shields.io/pypi/v/pytest-redis.svg\n    :target: https://pypi.python.org/pypi/pytest-redis/\n    :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/wheel/pytest-redis.svg\n    :target: https://pypi.python.org/pypi/pytest-redis/\n    :alt: Wheel Status\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-redis.svg\n    :target: https://pypi.python.org/pypi/pytest-redis/\n    :alt: Supported Python Versions\n\n.. image:: https://img.shields.io/pypi/l/pytest-redis.svg\n    :target: https://pypi.python.org/pypi/pytest-redis/\n    :alt: License\n\nWhat is this?\n=============\n\nThis is a pytest plugin that enables you to test your code that relies on a running Redis database.\nIt allows you to specify additional fixtures for Redis process and client.\n\nQuickstart: first test\n----------------------\n\n1) Install the plugin and your test dependencies (as you normally do for your project).\n2) Ensure Redis is available (local install or container). The ``redis-server`` executable\n   must be on PATH, or pass it explicitly with ``--redis-exec``. If Redis can't be found or\n   started, pytest-redis raises ``RedisMisconfigured``.\n3) Create a test that uses the built-in fixture:\n\n.. code-block:: python\n\n    def test_can_connect(redisdb):\n        redisdb.set(\"ping\", \"pong\")\n        assert redisdb.get(\"ping\") == b\"pong\"\n\n4) Run your tests:\n\n.. code-block:: shell\n\n    pytest\n\nThe plugin contains three fixtures:\n\n* **redisdb** - function-scoped client fixture that cleans all databases after each test.\n* **redis_proc** - session-scoped fixture that starts Redis at first use and stops at the end\n  of the tests.\n* **redis_noproc** - no-process fixture that connects to an already running Redis instance.\n\nSimply include one of these fixtures in your test fixture list.\n\n\n\n.. image:: https://raw.githubusercontent.com/dbfixtures/pytest-redis/main/docs/images/architecture.svg\n    :alt: Project Architecture Diagram\n    :align: center\n\n\nHow to use\n==========\n\n.. code-block:: python\n\n    #\n    def test_redis(redisdb):\n        \"\"\"Check that it's actually working on redis database.\"\"\"\n        redisdb.set('test1', 'test')\n        redisdb.set('test2', 'test')\n\n        my_functionality = MyRedisBasedComponent()\n        my_functionality.do_something()\n        assert my_functionality.did_something\n\n        assert redisdb.get(\"did_it\") == 1\n\nThe example above works as follows:\n\n1. pytest runs tests\n2. redis_proc starts redis database server\n3. redisdb creates client connection to the server\n4. test itself runs and finishes\n5. redisdb cleans up the redis\n6. redis_proc stops server (if that was the last test using it)\n7. pytest ends running tests\n\nYou can also create additional redis client and process fixtures if you need to:\n\n\n.. code-block:: python\n\n    from pytest_redis import factories\n\n    redis_my_proc = factories.redis_proc(port=None)\n    redis_my = factories.redisdb('redis_my_proc')\n\n    def test_my_redis(redis_my):\n        \"\"\"Check that it's actually working on redis database.\"\"\"\n        redis_my.set('test1', 'test')\n        redis_my.set('test2', 'test')\n\n        my_functionality = MyRedisBasedComponent()\n        my_functionality.do_something()\n        assert my_functionality.did_something\n\n        assert redis_my.get(\"did_it\") == 1\n\n.. note::\n\n    Each Redis process fixture can be configured in a different way than the others through the fixture factory arguments.\n\n\nConnecting to already existing redis database\n---------------------------------------------\n\nSome projects use already running Redis servers (i.e. on Docker instances).\nIn order to connect to them, one would be using the ``redis_noproc`` fixture.\n\n.. code-block:: python\n\n    redis_external = factories.redisdb('redis_noproc')\n\n    def test_redis(redis_external):\n        \"\"\"Check that it's actually working on redis database.\"\"\"\n        redis_external.set('test1', 'test')\n        redis_external.set('test2', 'test')\n\n        my_functionality = MyRedisBasedComponent()\n        my_functionality.do_something()\n        assert my_functionality.did_something\n\n        assert redis_external.get(\"did_it\") == 1\n\nStandard configuration options apply to it. Note that the `modules` configuration option\nhas no effect with the ``redis_noproc`` fixture, it is the responsibility of the already\nrunning redis server to be properly started with extension modules, if needed.\n\nBy default the ``redis_noproc`` fixture would connect to Redis\ninstance using **6379** port attempting to make a successful socket\nconnection within **15 seconds**. The fixture will block your test run\nwithin this timeout window. You can overwrite the timeout like so:\n\n\n.. code-block:: python\n\n    # set the blocking wait to 5 seconds\n    redis_noproc = factories.redis_noproc(startup_timeout=5)\n    redis_external = factories.redisdb('redis_noproc')\n\n    def test_redis(redis_external):\n        \"\"\"Check that it's actually working on redis database.\"\"\"\n        redis_external.set('test1', 'test')\n        # etc etc\n\nThese are the configuration options that are working on all levels with the ``redis_noproc`` fixture:\n\nConfiguration\n=============\n\nYou can define your settings in three ways, it's fixture factory argument, command line option and pytest.ini configuration option.\nYou can pick which you prefer, but remember that these settings are handled in the following order:\n\n    * ``Fixture factory argument``\n    * ``Command line option``\n    * ``Configuration option in your pytest.ini file``\n\n.. list-table:: Configuration options\n   :header-rows: 1\n\n   * - Redis server option\n     - Fixture factory argument\n     - Command line option\n     - pytest.ini option\n     - Noop process fixture\n     - Default\n   * - executable\n     - executable\n     - --redis-exec\n     - redis_exec\n     - -\n     - Look in PATH for redis-server via shutil.which\n   * - host\n     - host\n     - --redis-host\n     - redis_host\n     - host\n     - 127.0.0.1\n   * - port\n     - port\n     - --redis-port\n     - redis_port\n     - port\n     - random\n   * - Free port search count\n     - port_search_count\n     - --redis-port-search-count\n     - redis_port_search_count\n     - -\n     - 5\n   * - username\n     - username\n     - --redis-username\n     - redis_username\n     - username\n     - None\n   * - password\n     - password\n     - --redis-password\n     - redis_password\n     - password\n     - None\n   * - connection timeout\n     - timeout\n     - --redis-timeout\n     - redis_timeout\n     - -\n     - 15\n   * - number of databases\n     - db_count\n     - --redis-db-count\n     - redis_db_count\n     - -\n     - 8\n   * - Whether to enable logging to the system logger\n     - syslog\n     - --redis-syslog\n     - redis_syslog\n     - -\n     - False\n   * - Redis log verbosity level\n     - loglevel\n     - --redis-loglevel\n     - redis_loglevel\n     - -\n     - notice\n   * - Compress dump files\n     - compress\n     - --redis-compress\n     - redis_compress\n     - -\n     - True\n   * - Add checksum to RDB files\n     - checksum\n     - --redis-rdbcompress\n     - redis_rdbchecksum\n     - -\n     - False\n   * - Save configuration\n     - save\n     - --redis-save\n     - redis_save\n     - -\n     - \"\"\n   * - Redis test instance data directory path\n     - datadir\n     - --redis-datadir\n     - redis_datadir\n     - -\n     - \"\"\n   * - Redis test instance extension module(s) path\n     - modules (list of paths)\n     - --redis-modules (comma-separated string)\n     - redis_modules (comma-separated string)\n     - -\n     - \"\"\n\nExample usage:\n\n* pass it as an argument in your own fixture\n\n.. code-block:: python\n\n    redis_proc = factories.redis_proc(port=8888)\n\n* use ``--redis-port`` command line option when you run your tests\n\n.. code-block:: bash\n\n    py.test tests --redis-port=8888\n\n\n* specify your port as ``redis_port`` in your ``pytest.ini`` file.\n\n    To do so, put a line like the following under the ``[pytest]`` section of your ``pytest.ini``:\n\n.. code-block:: ini\n\n    [pytest]\n    redis_port = 8888\n\nOptions below are for configuring redis client fixture.\n\n+---------------------+--------------------------+---------------------+-------------------+---------+\n| Redis client option | Fixture factory argument | Command line option | pytest.ini option | Default |\n+=====================+==========================+=====================+===================+=========+\n| decode_response     | decode                   | --redis-decode      | redis_decode      | False   |\n+---------------------+--------------------------+---------------------+-------------------+---------+\n\nRelease\n=======\n\nInstall pipenv and --dev dependencies first, Then run:\n\n.. code-block:: bash\n\n    pipenv run tbump [NEW_VERSION]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbfixtures%2Fpytest-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbfixtures%2Fpytest-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbfixtures%2Fpytest-redis/lists"}