commit
cbd33857b6
2 changed files with 14 additions and 8 deletions
|
@ -37,11 +37,17 @@ def key_prefix(request, redis):
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def cleanup_keys(request):
|
def cleanup_keys(request):
|
||||||
def cleanup_keys():
|
# Always use the sync Redis connection with finalizer. Setting up an
|
||||||
# Always use the sync Redis connection with finalizer. Setting up an
|
# async finalizer should work, but I'm not suer how yet!
|
||||||
# async finalizer should work, but I'm not suer how yet!
|
from redis_om.connections import get_redis_connection as get_sync_redis
|
||||||
from redis_om.connections import get_redis_connection as get_sync_redis
|
|
||||||
|
|
||||||
_delete_test_keys(TEST_PREFIX, get_sync_redis())
|
# Increment for every pytest-xdist worker
|
||||||
|
conn = get_sync_redis()
|
||||||
|
once_key = f"{TEST_PREFIX}:cleanup_keys"
|
||||||
|
conn.incr(once_key)
|
||||||
|
|
||||||
request.addfinalizer(cleanup_keys)
|
yield
|
||||||
|
|
||||||
|
# Delete keys only once
|
||||||
|
if conn.decr(once_key) == 0:
|
||||||
|
_delete_test_keys(TEST_PREFIX, conn)
|
||||||
|
|
|
@ -137,7 +137,7 @@ async def test_full_text_search_queries(members, m):
|
||||||
|
|
||||||
assert actual == [member1]
|
assert actual == [member1]
|
||||||
|
|
||||||
actual = await (m.Member.find(~(m.Member.bio % "anxious")).all())
|
actual = await (m.Member.find(~(m.Member.bio % "anxious")).sort_by("age").all())
|
||||||
|
|
||||||
assert actual == [member1, member3]
|
assert actual == [member1, member3]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue