File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -37,11 +37,18 @@ def key_prefix(request, redis):
37
37
38
38
@pytest .fixture (scope = "session" , autouse = True )
39
39
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
44
43
45
- _delete_test_keys (TEST_PREFIX , get_sync_redis ())
44
+ # Increment for every pytest-xdist worker
45
+ redis = get_sync_redis ()
46
+ once_key = f"{ TEST_PREFIX } :cleanup_keys"
47
+ redis .incr (once_key )
46
48
47
- request .addfinalizer (cleanup_keys )
49
+ yield
50
+
51
+ # Delete keys only once
52
+ if redis .decr (once_key ) == 0 :
53
+ _delete_test_keys (TEST_PREFIX , redis )
54
+ redis .delete (once_key )
You can’t perform that action at this time.
0 commit comments