1
1
import os
2
2
import pytest
3
- import asyncio
4
3
5
4
from redisvl .redis .connection import RedisConnectionFactory
6
5
from testcontainers .compose import DockerCompose
7
6
8
7
9
-
10
8
@pytest .fixture (scope = "session" , autouse = True )
11
9
def redis_container (request ):
12
10
"""
13
11
Create a unique Compose project for each xdist worker by setting
14
12
COMPOSE_PROJECT_NAME. That prevents collisions on container/volume names.
15
13
"""
16
- # In xdist, the config has "workerid" in workerinput. For the main (non-xdist)
17
- # process, 'workerid' is often 'master' or something similar.
14
+ # In xdist, the config has "workerid" in workerinput
18
15
worker_id = request .config .workerinput .get ("workerid" , "master" )
19
16
20
17
# Set the Compose project name so containers do not clash across workers
@@ -26,21 +23,11 @@ def redis_container(request):
26
23
compose_file_name = "docker-compose.yml" ,
27
24
pull = True ,
28
25
)
29
-
30
26
compose .start ()
31
27
32
- # If you mapped the container port 6379:6379 in docker-compose.yml,
33
- # you might have collisions across workers. If you rely on ephemeral
34
- # host ports, remove the `ports:` block in docker-compose.yml and do:
35
- redis_host , redis_port = compose .get_service_host_and_port ("redis" , 6379 )
36
- #redis_url = f"redis://{redis_host}:{redis_port}"
37
- #os.environ["REDIS_URL"] = redis_url
38
-
39
28
yield compose
40
29
41
30
compose .stop ()
42
- # Optionally, clean up the COMPOSE_PROJECT_NAME you set:
43
- os .environ .pop ("COMPOSE_PROJECT_NAME" , None )
44
31
45
32
46
33
@pytest .fixture (scope = "session" )
0 commit comments