pytest-redislite
pytest-redislite — a simple pytest plugin to help you test your projects using Redis.
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_pathredis_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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_redislite-0.2.2.tar.gz | 41.0 kB | Without provenance | Details for pytest_redislite-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_redislite-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for pytest_redislite-0.2.2-py3-none-any.whl |
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}
|
Security for pytest-redislite 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.