Skip to main content

pytest-redislite

pytest-redislite — a simple pytest plugin to help you test your projects using Redis.

Tests Status PYPI Version Python Versions

Features

  • Automatically starts/ends Redis for your tests using Redislite
  • Flushes Redis database between tests automatically
  • Fast fixture teardown (bypasses slow redislite graceful shutdown)

Requirements

  • Python >= 3.10

Installation

pip install pytest-redislite

Usage

When installed, the plugin provides the redis_url fixture:

def test_code_with_redis(redis_url):
    from redis import Redis

    redis_client = Redis.from_url(redis_url)
    redis_client.set("key", "value")
    assert redis_client.get("key") == b"value"

The Redis server is started once per test session and cleaned up automatically after all tests finish.

You can also use redis_url in your own fixtures to set up Redis-backed integrations (for example, a cache client or task queue broker):

import pytest
from redis import Redis

@pytest.fixture(scope="session")
def cache(redis_url):
    client = Redis.from_url(redis_url, decode_responses=True)
    yield client
    client.close()

def test_cache_set_and_get(cache):
    cache.set("key", "value")
    assert cache.get("key") == "value"

Configuration

The plugin supports pytest command-line options:

  • --redis-path: Path to the Redis database file
  • --redis-socket-path: Path to the Redis Unix socket

And equivalent pytest.ini / pyproject.toml options:

  • redis_path
  • redis_socket_path

Fixtures

Fixture Scope Description
redis_server session redislite.Redis instance managing the server lifecycle
redis_url session Unix socket URL for connecting to the running server
redis_factory session Context manager to manually start/shutdown a redislite server

Auto-flush data between tests

By default, the plugin erases all Redis data between tests. To disable this, override the redis_autoflash fixture:

import pytest

@pytest.fixture
def redis_autoflash():
    return False

You can scope this override to a module or the entire test session.

Development

This project uses uv for dependency management and builds.

# Install dependencies
uv sync --group dev

# Run tests
uv run pytest tests.py

# Run all tests (including no-autoflash scenario)
uv run pytest tests.py tests_no_autoflash.py

# Build and publish
uv build
uv publish

Bug tracker

If you have any suggestions, bug reports, or annoyances please report them to the issue tracker at https: //github.com/klen/pytest-redislite/issues

Contributing

Development of the project happens at: https://github.com/klen/pytest-redislite

License

Licensed under a MIT License

Metadata

Release files for pytest-redislite 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-redislite 0.2.2
File Size Uploaded
pytest_redislite-0.2.2.tar.gz 41.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-redislite 0.2.2
File Interpreter ABI Platform
pytest_redislite-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 44.5 kB

Release files / pytest_redislite-0.2.2.tar.gz

Download URL pytest_redislite-0.2.2.tar.gz
Size 41.0 kB
Tags Source
SHA-256 checksum
How to use checksums
848119dc895f25308fd34ec7d78ebd4c6b620adb42e0507e63282f4981fe8196
BLAKE2b-256 checksum
How to use checksums
bf2e2709711e5367c500427194e41788d6dd891ef28bf3e76c8c3366dfde2786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pytest_redislite-0.2.2-py3-none-any.whl

Download URL pytest_redislite-0.2.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac027c3f4b77afd0f9e799fb0b3710d032bb36f7bbf49e15e4413309b83ad1a7
BLAKE2b-256 checksum
How to use checksums
a3f567402b12397adc5cf5941c9b8bc57aa4ad240b9f3cf0e4f4c9e52cfa8249
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page