@@ -207,7 +207,7 @@ def datarow(dataset, image_url):
207207 },
208208 ])
209209 task .wait_till_done ()
210- dr = next ( dataset .data_rows ())
210+ dr = dataset .data_rows (). get_one ( )
211211 yield dr
212212 dr .delete ()
213213
@@ -304,7 +304,7 @@ def configured_project(project, client, rand_gen, image_url):
304304
305305@pytest .fixture
306306def configured_project_with_label (client , rand_gen , image_url , project , dataset ,
307- datarow ):
307+ datarow , wait_for_label_processing ):
308308 """Project with a connected dataset, having one datarow
309309 Project contains an ontology with 1 bbox tool
310310 Additionally includes a create_label method for any needed extra labels
@@ -348,8 +348,8 @@ def create_label():
348348
349349 project .create_label = create_label
350350 project .create_label ()
351- label = project . labels (). get_one ()
352- assert label is not None , "Cannot fetch created label"
351+ label = wait_for_label_processing ( project )[ 0 ]
352+
353353 yield [project , dataset , datarow , label ]
354354
355355 for label in project .labels ():
@@ -407,3 +407,56 @@ def configured_project_with_complex_ontology(client, rand_gen, image_url):
407407 yield [project , data_row ]
408408 dataset .delete ()
409409 project .delete ()
410+
411+
412+ @pytest .fixture
413+ def wait_for_data_row_processing ():
414+ """
415+ Do not use. Only for testing.
416+
417+ Returns DataRow after waiting for it to finish processing media_attributes.
418+ Some tests, specifically ones that rely on label export, rely on
419+ DataRow be fully processed with media_attributes
420+ """
421+
422+ def func (client , data_row ):
423+ data_row_id = data_row .uid
424+ timeout_seconds = 60
425+ while True :
426+ data_row = client .get_data_row (data_row_id )
427+ if data_row .media_attributes :
428+ return data_row
429+ timeout_seconds -= 2
430+ if timeout_seconds <= 0 :
431+ raise TimeoutError (
432+ f"Timed out waiting for DataRow '{ data_row_id } ' to finish processing media_attributes"
433+ )
434+ time .sleep (2 )
435+
436+ return func
437+
438+
439+ @pytest .fixture
440+ def wait_for_label_processing ():
441+ """
442+ Do not use. Only for testing.
443+
444+ Returns project's labels as a list after waiting for them to finish processing.
445+ If `project.labels()` is called before label is fully processed,
446+ it may return an empty set
447+ """
448+
449+ def func (project ):
450+ timeout_seconds = 10
451+ while True :
452+ labels = list (project .labels ())
453+ if len (labels ) > 0 :
454+ return labels
455+ timeout_seconds -= 2
456+ if timeout_seconds <= 0 :
457+ raise TimeoutError (
458+ f"Timed out waiting for label for project '{ project .uid } ' to finish processing"
459+ )
460+ time .sleep (2 )
461+
462+ return func
0 commit comments