2021-10-21 08:24:31 +02:00
|
|
|
import random
|
|
|
|
|
2021-09-16 02:41:45 +02:00
|
|
|
import pytest
|
|
|
|
|
2021-10-22 15:33:05 +02:00
|
|
|
from redis_om.connections import get_redis_connection
|
2021-09-16 02:41:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2021-10-22 15:33:05 +02:00
|
|
|
def redis(event_loop):
|
2021-09-16 02:41:45 +02:00
|
|
|
yield get_redis_connection()
|
|
|
|
|
|
|
|
|
2021-10-22 15:33:05 +02:00
|
|
|
async def _delete_test_keys(prefix: str, conn):
|
2021-10-21 08:24:31 +02:00
|
|
|
keys = []
|
2021-10-22 15:33:05 +02:00
|
|
|
async 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-09-16 02:41:45 +02:00
|
|
|
|
2021-10-21 08:24:31 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def key_prefix(redis):
|
2021-10-22 15:33:05 +02:00
|
|
|
key_prefix = f"redis-om:{random.random()}"
|
2021-10-21 08:24:31 +02:00
|
|
|
yield key_prefix
|
2021-09-16 02:41:45 +02:00
|
|
|
|
2021-10-21 08:31:11 +02:00
|
|
|
|
2021-10-21 08:24:31 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
2021-10-22 15:33:05 +02:00
|
|
|
async def delete_test_keys(redis, request, key_prefix):
|
|
|
|
await _delete_test_keys(key_prefix, redis)
|