redis-om-python/tests/conftest.py

32 lines
635 B
Python
Raw Normal View History

2021-10-21 08:24:31 +02:00
import random
import pytest
from redis import Redis
from redis_developer.connections import get_redis_connection
@pytest.fixture
def redis():
yield get_redis_connection()
def _delete_test_keys(prefix: str, conn: Redis):
2021-10-21 08:24:31 +02:00
keys = []
for key in conn.scan_iter(f"{prefix}:*"):
2021-10-21 08:24:31 +02:00
keys.append(key)
if keys:
conn.delete(*keys)
2021-10-21 08:24:31 +02:00
@pytest.fixture
def key_prefix(redis):
key_prefix = f"redis-developer:{random.random()}"
yield key_prefix
_delete_test_keys(key_prefix, redis)
2021-10-21 08:31:11 +02:00
2021-10-21 08:24:31 +02:00
@pytest.fixture(autouse=True)
def delete_test_keys(redis, request, key_prefix):
_delete_test_keys(key_prefix, redis)