Skip to content

Commit cbd3385

Browse files
author
Simon Prickett
authored
Merge pull request #220 from moznuy/fix/87
Fixes #87
2 parents 878490a + 838a712 commit cbd3385

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

tests/conftest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ def key_prefix(request, redis):
3737

3838
@pytest.fixture(scope="session", autouse=True)
3939
def cleanup_keys(request):
40-
def cleanup_keys():
41-
# Always use the sync Redis connection with finalizer. Setting up an
42-
# async finalizer should work, but I'm not suer how yet!
43-
from redis_om.connections import get_redis_connection as get_sync_redis
40+
# Always use the sync Redis connection with finalizer. Setting up an
41+
# async finalizer should work, but I'm not suer how yet!
42+
from redis_om.connections import get_redis_connection as get_sync_redis
4443

45-
_delete_test_keys(TEST_PREFIX, get_sync_redis())
44+
# Increment for every pytest-xdist worker
45+
conn = get_sync_redis()
46+
once_key = f"{TEST_PREFIX}:cleanup_keys"
47+
conn.incr(once_key)
4648

47-
request.addfinalizer(cleanup_keys)
49+
yield
50+
51+
# Delete keys only once
52+
if conn.decr(once_key) == 0:
53+
_delete_test_keys(TEST_PREFIX, conn)

tests/test_hash_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async def test_full_text_search_queries(members, m):
137137

138138
assert actual == [member1]
139139

140-
actual = await (m.Member.find(~(m.Member.bio % "anxious")).all())
140+
actual = await (m.Member.find(~(m.Member.bio % "anxious")).sort_by("age").all())
141141

142142
assert actual == [member1, member3]
143143

@@ -433,7 +433,7 @@ async def test_all_pks(m):
433433
bio="This is a test user to be deleted.",
434434
)
435435

436-
await member1.save()
436+
await member1.save()
437437

438438
pk_list = []
439439
async for pk in await m.Member.all_pks():

0 commit comments

Comments
 (0)