@@ -14,11 +14,13 @@ def set_tokenizers_parallelism():
14
14
@pytest .fixture (scope = "session" , autouse = True )
15
15
def redis_container (request ):
16
16
"""
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.
19
20
"""
20
21
# 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" )
22
24
23
25
# Set the Compose project name so containers do not clash across workers
24
26
os .environ ["COMPOSE_PROJECT_NAME" ] = f"redis_test_{ worker_id } "
@@ -45,6 +47,7 @@ def redis_url(redis_container):
45
47
host , port = redis_container .get_service_host_and_port ("redis" , 6379 )
46
48
return f"redis://{ host } :{ port } "
47
49
50
+
48
51
@pytest .fixture
49
52
async def async_client (redis_url ):
50
53
"""
@@ -58,6 +61,7 @@ async def async_client(redis_url):
58
61
if "Event loop is closed" not in str (e ):
59
62
raise
60
63
64
+
61
65
@pytest .fixture
62
66
def client (redis_url ):
63
67
"""
@@ -67,110 +71,120 @@ def client(redis_url):
67
71
yield conn
68
72
conn .close ()
69
73
74
+
70
75
@pytest .fixture
71
76
def openai_key ():
72
77
return os .getenv ("OPENAI_API_KEY" )
73
78
79
+
74
80
@pytest .fixture
75
81
def openai_version ():
76
82
return os .getenv ("OPENAI_API_VERSION" )
77
83
84
+
78
85
@pytest .fixture
79
86
def azure_endpoint ():
80
87
return os .getenv ("AZURE_OPENAI_ENDPOINT" )
81
88
89
+
82
90
@pytest .fixture
83
91
def cohere_key ():
84
92
return os .getenv ("COHERE_API_KEY" )
85
93
94
+
86
95
@pytest .fixture
87
96
def mistral_key ():
88
97
return os .getenv ("MISTRAL_API_KEY" )
89
98
99
+
90
100
@pytest .fixture
91
101
def gcp_location ():
92
102
return os .getenv ("GCP_LOCATION" )
93
103
104
+
94
105
@pytest .fixture
95
106
def gcp_project_id ():
96
107
return os .getenv ("GCP_PROJECT_ID" )
97
108
109
+
98
110
@pytest .fixture
99
111
def aws_credentials ():
100
112
return {
101
113
"aws_access_key_id" : os .getenv ("AWS_ACCESS_KEY_ID" ),
102
114
"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" ),
104
116
}
105
117
118
+
106
119
@pytest .fixture
107
120
def sample_data ():
108
121
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
+
166
180
167
181
@pytest .fixture
168
182
def clear_db (redis ):
169
183
redis .flushall ()
170
184
yield
171
185
redis .flushall ()
172
186
187
+
173
188
@pytest .fixture
174
189
def app_name ():
175
190
return "test_app"
176
-
0 commit comments