Run tests across multiple cores/CPUs

This commit is contained in:
Andrew Brookins 2021-10-20 23:24:31 -07:00
parent bd24050e3f
commit 2ffd4e6f5a
7 changed files with 368 additions and 292 deletions

View file

@ -1,13 +1,9 @@
import random
import pytest
from redis import Redis
from redis_developer.connections import get_redis_connection
from redis_developer.model.migrations.migrator import Migrator
@pytest.fixture(scope="module", autouse=True)
def migrations():
Migrator().run()
@pytest.fixture
@ -15,16 +11,20 @@ def redis():
yield get_redis_connection()
@pytest.fixture
def key_prefix():
yield "redis-developer"
def _delete_test_keys(prefix: str, conn: Redis):
keys = []
for key in conn.scan_iter(f"{prefix}:*"):
conn.delete(key)
keys.append(key)
if keys:
conn.delete(*keys)
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture
def key_prefix(redis):
key_prefix = f"redis-developer:{random.random()}"
yield key_prefix
_delete_test_keys(key_prefix, redis)
@pytest.fixture(autouse=True)
def delete_test_keys(redis, request, key_prefix):
_delete_test_keys(key_prefix, redis)