Skip to content

Commit f9a3e92

Browse files
authored
Only check for workerid if workerinput is present (#274)
1 parent 3723cf0 commit f9a3e92

File tree

1 file changed

+76
-62
lines changed

1 file changed

+76
-62
lines changed

conftest.py

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def set_tokenizers_parallelism():
1414
@pytest.fixture(scope="session", autouse=True)
1515
def redis_container(request):
1616
"""
17-
Create a unique Compose project for each xdist worker by setting
18-
COMPOSE_PROJECT_NAME. That prevents collisions on container/volume names.
17+
If using xdist, create a unique Compose project for each xdist worker by
18+
setting COMPOSE_PROJECT_NAME. That prevents collisions on container/volume
19+
names.
1920
"""
2021
# In xdist, the config has "workerid" in workerinput
21-
worker_id = request.config.workerinput.get("workerid", "master")
22+
workerinput = getattr(request.config, "workerinput", {})
23+
worker_id = workerinput.get("workerid", "master")
2224

2325
# Set the Compose project name so containers do not clash across workers
2426
os.environ["COMPOSE_PROJECT_NAME"] = f"redis_test_{worker_id}"
@@ -45,6 +47,7 @@ def redis_url(redis_container):
4547
host, port = redis_container.get_service_host_and_port("redis", 6379)
4648
return f"redis://{host}:{port}"
4749

50+
4851
@pytest.fixture
4952
async def async_client(redis_url):
5053
"""
@@ -58,6 +61,7 @@ async def async_client(redis_url):
5861
if "Event loop is closed" not in str(e):
5962
raise
6063

64+
6165
@pytest.fixture
6266
def client(redis_url):
6367
"""
@@ -67,110 +71,120 @@ def client(redis_url):
6771
yield conn
6872
conn.close()
6973

74+
7075
@pytest.fixture
7176
def openai_key():
7277
return os.getenv("OPENAI_API_KEY")
7378

79+
7480
@pytest.fixture
7581
def openai_version():
7682
return os.getenv("OPENAI_API_VERSION")
7783

84+
7885
@pytest.fixture
7986
def azure_endpoint():
8087
return os.getenv("AZURE_OPENAI_ENDPOINT")
8188

89+
8290
@pytest.fixture
8391
def cohere_key():
8492
return os.getenv("COHERE_API_KEY")
8593

94+
8695
@pytest.fixture
8796
def mistral_key():
8897
return os.getenv("MISTRAL_API_KEY")
8998

99+
90100
@pytest.fixture
91101
def gcp_location():
92102
return os.getenv("GCP_LOCATION")
93103

104+
94105
@pytest.fixture
95106
def gcp_project_id():
96107
return os.getenv("GCP_PROJECT_ID")
97108

109+
98110
@pytest.fixture
99111
def aws_credentials():
100112
return {
101113
"aws_access_key_id": os.getenv("AWS_ACCESS_KEY_ID"),
102114
"aws_secret_access_key": os.getenv("AWS_SECRET_ACCESS_KEY"),
103-
"aws_region": os.getenv("AWS_REGION", "us-east-1")
115+
"aws_region": os.getenv("AWS_REGION", "us-east-1"),
104116
}
105117

118+
106119
@pytest.fixture
107120
def sample_data():
108121
return [
109-
{
110-
"user": "john",
111-
"age": 18,
112-
"job": "engineer",
113-
"credit_score": "high",
114-
"location": "-122.4194,37.7749",
115-
"user_embedding": [0.1, 0.1, 0.5]
116-
},
117-
{
118-
"user": "mary",
119-
"age": 14,
120-
"job": "doctor",
121-
"credit_score": "low",
122-
"location": "-122.4194,37.7749",
123-
"user_embedding": [0.1, 0.1, 0.5]
124-
},
125-
{
126-
"user": "nancy",
127-
"age": 94,
128-
"job": "doctor",
129-
"credit_score": "high",
130-
"location": "-122.4194,37.7749",
131-
"user_embedding": [0.7, 0.1, 0.5]
132-
},
133-
{
134-
"user": "tyler",
135-
"age": 100,
136-
"job": "engineer",
137-
"credit_score": "high",
138-
"location": "-110.0839,37.3861",
139-
"user_embedding": [0.1, 0.4, 0.5]
140-
},
141-
{
142-
"user": "tim",
143-
"age": 12,
144-
"job": "dermatologist",
145-
"credit_score": "high",
146-
"location": "-110.0839,37.3861",
147-
"user_embedding": [0.4, 0.4, 0.5]
148-
},
149-
{
150-
"user": "taimur",
151-
"age": 15,
152-
"job": "CEO",
153-
"credit_score": "low",
154-
"location": "-110.0839,37.3861",
155-
"user_embedding": [0.6, 0.1, 0.5]
156-
},
157-
{
158-
"user": "joe",
159-
"age": 35,
160-
"job": "dentist",
161-
"credit_score": "medium",
162-
"location": "-110.0839,37.3861",
163-
"user_embedding": [0.9, 0.9, 0.1]
164-
},
165-
]
122+
{
123+
"user": "john",
124+
"age": 18,
125+
"job": "engineer",
126+
"credit_score": "high",
127+
"location": "-122.4194,37.7749",
128+
"user_embedding": [0.1, 0.1, 0.5],
129+
},
130+
{
131+
"user": "mary",
132+
"age": 14,
133+
"job": "doctor",
134+
"credit_score": "low",
135+
"location": "-122.4194,37.7749",
136+
"user_embedding": [0.1, 0.1, 0.5],
137+
},
138+
{
139+
"user": "nancy",
140+
"age": 94,
141+
"job": "doctor",
142+
"credit_score": "high",
143+
"location": "-122.4194,37.7749",
144+
"user_embedding": [0.7, 0.1, 0.5],
145+
},
146+
{
147+
"user": "tyler",
148+
"age": 100,
149+
"job": "engineer",
150+
"credit_score": "high",
151+
"location": "-110.0839,37.3861",
152+
"user_embedding": [0.1, 0.4, 0.5],
153+
},
154+
{
155+
"user": "tim",
156+
"age": 12,
157+
"job": "dermatologist",
158+
"credit_score": "high",
159+
"location": "-110.0839,37.3861",
160+
"user_embedding": [0.4, 0.4, 0.5],
161+
},
162+
{
163+
"user": "taimur",
164+
"age": 15,
165+
"job": "CEO",
166+
"credit_score": "low",
167+
"location": "-110.0839,37.3861",
168+
"user_embedding": [0.6, 0.1, 0.5],
169+
},
170+
{
171+
"user": "joe",
172+
"age": 35,
173+
"job": "dentist",
174+
"credit_score": "medium",
175+
"location": "-110.0839,37.3861",
176+
"user_embedding": [0.9, 0.9, 0.1],
177+
},
178+
]
179+
166180

167181
@pytest.fixture
168182
def clear_db(redis):
169183
redis.flushall()
170184
yield
171185
redis.flushall()
172186

187+
173188
@pytest.fixture
174189
def app_name():
175190
return "test_app"
176-

0 commit comments

Comments
 (0)