Skip to main content

Pytest plugin for testing code using Redis

Project description

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.

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

Project details


Download files

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

Source Distribution

pytest_redislite-0.2.1.tar.gz (40.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_redislite-0.2.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_redislite-0.2.1.tar.gz.

File metadata

  • Download URL: pytest_redislite-0.2.1.tar.gz
  • Upload date:
  • Size: 40.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pytest_redislite-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ee6f7d6c9c0ce7c1ff6e6d9388e4eff304a4fa3294f46dd5187fbe3fb94d31cc
MD5 ddbf63cba8814fb6d57c1214f8f1498b
BLAKE2b-256 c3fe8647cc1182ab60dd914021941e032d5490e2db4d778684dac394d69d2f52

See more details on using hashes here.

File details

Details for the file pytest_redislite-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_redislite-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pytest_redislite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73b2e5e91025bea00c94b1ad373b1c41620074d5eb77a8c01b96843b45e9cdaf
MD5 dde8777b0830286c1173716826fe2f83
BLAKE2b-256 d610fa0076192772862a96bb7017c31a8493b5b23ba096723e099038ce1f613c

See more details on using hashes here.

Supported by

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