7
7
import glob
8
8
import pathlib
9
9
import time
10
+
11
+ import requests
10
12
import pytest_mock
11
13
import tempfile
12
14
import simvue .client as svc
15
17
import simvue .api .objects as sv_api_obj
16
18
from simvue .api .objects .alert .base import AlertBase
17
19
18
- @pytest .mark .dependency
19
20
@pytest .mark .client
20
21
def test_get_events (create_test_run : tuple [sv_run .Run , dict ]) -> None :
21
22
client = svc .Client ()
22
23
assert client .get_events (run_id = create_test_run [1 ]["run_id" ])
23
24
24
25
25
- @pytest .mark .dependency
26
26
@pytest .mark .client
27
27
@pytest .mark .parametrize (
28
28
"from_run" , (True , False ), ids = ("from_run" , "all_runs" )
@@ -90,7 +90,6 @@ def test_get_alerts(
90
90
assert len (_alerts ) == 2
91
91
assert f"user_alert_2_{ unique_id } " in _alerts
92
92
93
- @pytest .mark .dependency
94
93
@pytest .mark .client
95
94
def test_get_run_id_from_name (create_test_run : tuple [sv_run .Run , dict ]) -> None :
96
95
client = svc .Client ()
@@ -100,7 +99,6 @@ def test_get_run_id_from_name(create_test_run: tuple[sv_run.Run, dict]) -> None:
100
99
)
101
100
102
101
103
- @pytest .mark .dependency
104
102
@pytest .mark .client
105
103
@pytest .mark .parametrize (
106
104
"aggregate,use_name_labels" ,
@@ -138,7 +136,6 @@ def test_get_metric_values(
138
136
assert create_test_run [1 ]["run_id" ] in _runs
139
137
140
138
141
- @pytest .mark .dependency
142
139
@pytest .mark .client
143
140
def test_plot_metrics (create_test_run : tuple [sv_run .Run , dict ]) -> None :
144
141
try :
@@ -154,7 +151,6 @@ def test_plot_metrics(create_test_run: tuple[sv_run.Run, dict]) -> None:
154
151
)
155
152
156
153
157
- @pytest .mark .dependency
158
154
@pytest .mark .client
159
155
@pytest .mark .parametrize (
160
156
"sorting" , ([("metadata.test_identifier" , True )], [("name" , True ), ("created" , True )], None ),
@@ -166,7 +162,6 @@ def test_get_artifacts_entries(create_test_run: tuple[sv_run.Run, dict], sorting
166
162
assert client .get_artifact (create_test_run [1 ]["run_id" ], name = "test_attributes" )
167
163
168
164
169
- @pytest .mark .dependency
170
165
@pytest .mark .client
171
166
@pytest .mark .parametrize ("file_id" , (1 , 2 , 3 ), ids = lambda x : f"file_{ x } " )
172
167
def test_get_artifact_as_file (
@@ -183,7 +178,6 @@ def test_get_artifact_as_file(
183
178
assert pathlib .Path (tempd ).joinpath (_file_name ).exists (), f"Failed to download '{ _file_name } '"
184
179
185
180
186
- @pytest .mark .dependency
187
181
@pytest .mark .client
188
182
@pytest .mark .parametrize ("category" , (None , "code" , "input" , "output" ))
189
183
def test_get_artifacts_as_files (
@@ -213,7 +207,6 @@ def test_get_artifacts_as_files(
213
207
assert create_test_run [1 ][file ] not in files
214
208
215
209
216
- @pytest .mark .dependency
217
210
@pytest .mark .client
218
211
@pytest .mark .parametrize (
219
212
"output_format,sorting" ,
@@ -235,14 +228,12 @@ def test_get_runs(create_test_run: tuple[sv_run.Run, dict], output_format: str,
235
228
assert _result
236
229
237
230
238
- @pytest .mark .dependency
239
231
@pytest .mark .client
240
232
def test_get_run (create_test_run : tuple [sv_run .Run , dict ]) -> None :
241
233
client = svc .Client ()
242
234
assert client .get_run (run_id = create_test_run [1 ]["run_id" ])
243
235
244
236
245
- @pytest .mark .dependency
246
237
@pytest .mark .client
247
238
@pytest .mark .parametrize (
248
239
"sorting" , (None , [("metadata.test_identifier" , True ), ("path" , True )], [("modified" , False )]),
@@ -256,24 +247,32 @@ def test_get_folders(create_test_run: tuple[sv_run.Run, dict], sorting: list[tup
256
247
assert client .get_folder (_folder .path )
257
248
258
249
259
- @pytest .mark .dependency
260
250
@pytest .mark .client
261
251
def test_get_metrics_names (create_test_run : tuple [sv_run .Run , dict ]) -> None :
262
252
client = svc .Client ()
263
- time .sleep (1 )
264
- assert list (client .get_metrics_names (create_test_run [1 ]["run_id" ]))
253
+ attempts : int = 0
254
+
255
+ while not list (client .get_metrics_names (create_test_run [1 ]["run_id" ])) and attempts < 10 :
256
+ time .sleep (1 )
257
+ attempts += 1
258
+
259
+ if attempts >= 10 :
260
+ raise AssertionError ("Failed to retrieve metric name." )
265
261
266
262
267
- @pytest .mark .dependency
268
263
@pytest .mark .client
269
264
def test_get_tag (create_plain_run : tuple [sv_run .Run , dict ]) -> None :
270
265
_ , run_data = create_plain_run
271
266
client = svc .Client ()
272
- time .sleep (1.0 )
273
- assert any (tag .name == run_data ["tags" ][- 1 ] for _ , tag in client .get_tags ())
267
+ attempts : int = 0
268
+ while not any (tag .name == run_data ["tags" ][- 1 ] for _ , tag in client .get_tags ()) and attempts < 10 :
269
+ time .sleep (1 )
270
+ attempts += 1
271
+
272
+ if attempts >= 10 :
273
+ raise AssertionError ("Failed to retrieve tag." )
274
274
275
275
276
- @pytest .mark .dependency
277
276
@pytest .mark .client
278
277
def test_run_deletion () -> None :
279
278
run = sv_run .Run ()
@@ -286,7 +285,6 @@ def test_run_deletion() -> None:
286
285
client .get_run (run .id )
287
286
288
287
289
- @pytest .mark .dependency
290
288
@pytest .mark .client
291
289
def test_runs_deletion () -> None :
292
290
_runs = [sv_run .Run () for _ in range (5 )]
@@ -300,19 +298,21 @@ def test_runs_deletion() -> None:
300
298
client .get_run (run .id )
301
299
302
300
303
- @pytest .mark .dependency
304
301
@pytest .mark .client
305
302
def test_get_tags (create_plain_run : tuple [sv_run .Run , dict ]) -> None :
306
303
run , run_data = create_plain_run
307
304
tags = run_data ["tags" ]
308
305
run .close ()
309
- time .sleep (1.0 )
310
306
client = svc .Client ()
311
- retrieved = [t .name for _ , t in client .get_tags ()]
312
- assert all (t in retrieved for t in tags )
307
+ attempts = 0
308
+ while not all (f in [t .name for _ , t in client .get_tags ()] for f in tags ) and attempts < 10 :
309
+ time .sleep (1 )
310
+ attempts += 1
311
+
312
+ if attempts >= 10 :
313
+ raise AssertionError ("Failed to retrieve tags." )
313
314
314
315
315
- @pytest .mark .dependency
316
316
@pytest .mark .client
317
317
def test_folder_deletion () -> None :
318
318
run = sv_run .Run ()
@@ -359,7 +359,6 @@ def test_tag_deletion() -> None:
359
359
client .get_tag (tag_identifier )
360
360
361
361
362
- @pytest .mark .dependency
363
362
@pytest .mark .client
364
363
@pytest .mark .parametrize ("aggregate" , (True , False ), ids = ("aggregated" , "normal" ))
365
364
@pytest .mark .parametrize ("output_format" , ("dict" , "dataframe" ))
@@ -414,14 +413,11 @@ def test_abort_run(speedy_heartbeat, create_plain_run: tuple[sv_run.Run, dict])
414
413
run .update_tags ([f"delete_me_{ _uuid } " ])
415
414
_client = svc .Client ()
416
415
_client .abort_run (run .id , reason = "Test abort" )
417
- time .sleep (2 )
418
-
419
- # On some machines it might take a little longer so
420
- # try twice before accepting the abort failed
421
- try :
422
- assert run ._status == "terminated"
423
- except AssertionError :
424
- time .sleep (2 )
425
- assert run ._status == "terminated"
416
+ _attempts : int = 0
426
417
418
+ while run .status != "terminated" and _attempts < 10 :
419
+ time .sleep (1 )
420
+ _attempts += 1
421
+ if _attempts >= 10 :
422
+ raise AssertionError ("Failed to terminate run." )
427
423
0 commit comments