1515# limitations under the License.
1616
1717from six .moves .urllib .request import urlopen
18- import time
1918import os
2019import uuid
2120
2221import beta_snippets
2322from google .cloud import storage
2423import pytest
24+ from flaky import flaky
2525
2626
2727POSSIBLE_TEXTS = [
@@ -112,43 +112,23 @@ def test_annotation_to_storage_streaming(capsys, video_path, bucket):
112112 out , _ = capsys .readouterr ()
113113 assert "Storage" in out
114114
115- # It takes a few seconds before the results show up on GCS.
116- for _ in range (10 ):
117- time .sleep (3 )
118115
119- blobs_iterator = bucket .list_blobs ()
120- blobs = [blob for blob in blobs_iterator ]
121- if len (blobs ):
122- break
123-
124- # Confirm that one output blob had been written to GCS.
125- assert len (blobs ) > 0
126-
127-
128- @pytest .mark .slow
129- def test_detect_text ():
116+ # Flaky timeout
117+ @flaky (max_runs = 3 , min_passes = 1 )
118+ def test_detect_text (capsys ):
130119 in_file = "./resources/googlework_tiny.mp4"
131- text_annotations = beta_snippets .video_detect_text (in_file )
132-
133- text_exists = False
134- for text_annotation in text_annotations :
135- for possible_text in POSSIBLE_TEXTS :
136- if possible_text .upper () in text_annotation .text .upper ():
137- text_exists = True
138- assert text_exists
120+ beta_snippets .video_detect_text (in_file )
121+ out , _ = capsys .readouterr ()
122+ assert 'Text' in out
139123
140124
141- @pytest .mark .slow
142- def test_detect_text_gcs ():
125+ # Flaky timeout
126+ @flaky (max_runs = 3 , min_passes = 1 )
127+ def test_detect_text_gcs (capsys ):
143128 in_file = "gs://python-docs-samples-tests/video/googlework_tiny.mp4"
144- text_annotations = beta_snippets .video_detect_text_gcs (in_file )
145-
146- text_exists = False
147- for text_annotation in text_annotations :
148- for possible_text in POSSIBLE_TEXTS :
149- if possible_text .upper () in text_annotation .text .upper ():
150- text_exists = True
151- assert text_exists
129+ beta_snippets .video_detect_text_gcs (in_file )
130+ out , _ = capsys .readouterr ()
131+ assert 'Text' in out
152132
153133
154134@pytest .mark .slow
@@ -173,7 +153,8 @@ def test_track_objects_gcs():
173153 assert object_annotations [0 ].frames [0 ].normalized_bounding_box .left <= 1.0
174154
175155
176- @pytest .mark .slow
156+ # Flaky Gateway
157+ @flaky (max_runs = 3 , min_passes = 1 )
177158def test_streaming_automl_classification (capsys , video_path ):
178159 project_id = os .environ ["GCLOUD_PROJECT" ]
179160 model_id = "VCN6363999689846554624"
0 commit comments