Skip to content

Commit bfcc58b

Browse files
author
Takashi Matsuo
authored
testing: replace @flaky with @pytest.mark.flaky (#3496)
* testing: replace @flaky with @pytest.mark.flaky * lint * mark few tests as flaky that involves LRO polling. * lint
1 parent b7ff1e5 commit bfcc58b

File tree

13 files changed

+54
-43
lines changed

13 files changed

+54
-43
lines changed

blog/introduction_to_data_models_in_cloud_datastore/blog_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
import os
1515

16-
from flaky import flaky
16+
import pytest
1717

1818
from blog import main
1919

2020
PROJECT = os.environ['GCLOUD_PROJECT']
2121

2222

23-
@flaky
23+
@pytest.mark.flaky
2424
def test_main():
2525
main(PROJECT)

blog/introduction_to_data_models_in_cloud_datastore/wiki_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
import os
1515

16-
from flaky import flaky
16+
import pytest
1717

1818
from wiki import main
1919

2020
PROJECT = os.environ['GCLOUD_PROJECT']
2121

2222

23-
@flaky
23+
@pytest.mark.flaky
2424
def test_main():
2525
main(PROJECT)

dns/api/main_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import os
1515
import uuid
1616

17-
from flaky import flaky
1817
from google.cloud import dns
1918
from google.cloud.exceptions import NotFound
2019

@@ -57,7 +56,7 @@ def zone(client):
5756
pass
5857

5958

60-
@flaky
59+
@pytest.mark.flaky
6160
def test_create_zone(client):
6261
zone = main.create_zone(
6362
PROJECT,
@@ -70,7 +69,7 @@ def test_create_zone(client):
7069
assert zone.description == TEST_ZONE_DESCRIPTION
7170

7271

73-
@flaky
72+
@pytest.mark.flaky
7473
def test_get_zone(client, zone):
7574
zone = main.get_zone(PROJECT, TEST_ZONE_NAME)
7675

@@ -79,27 +78,27 @@ def test_get_zone(client, zone):
7978
assert zone.description == TEST_ZONE_DESCRIPTION
8079

8180

82-
@flaky
81+
@pytest.mark.flaky
8382
def test_list_zones(client, zone):
8483
zones = main.list_zones(PROJECT)
8584

8685
assert TEST_ZONE_NAME in zones
8786

8887

89-
@flaky
88+
@pytest.mark.flaky
9089
def test_list_resource_records(client, zone):
9190
records = main.list_resource_records(PROJECT, TEST_ZONE_NAME)
9291

9392
assert records
9493

9594

96-
@flaky
95+
@pytest.mark.flaky
9796
def test_list_changes(client, zone):
9897
changes = main.list_changes(PROJECT, TEST_ZONE_NAME)
9998

10099
assert changes
101100

102101

103-
@flaky
102+
@pytest.mark.flaky
104103
def test_delete_zone(client, zone):
105104
main.delete_zone(PROJECT, TEST_ZONE_NAME)

iap/iap_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Test script for Identity-Aware Proxy code samples."""
1616

17-
from flaky import flaky
17+
import pytest
1818

1919
import make_iap_request
2020
import validate_jwt
@@ -34,7 +34,7 @@
3434
IAP_PROJECT_NUMBER = '320431926067'
3535

3636

37-
@flaky
37+
@pytest.mark.flaky
3838
def test_main(capsys):
3939
# JWTs are obtained by IAP-protected applications whenever an
4040
# end-user makes a request. We've set up an app that echoes back

jobs/v3/api_client/quickstart_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from flaky import flaky
1514

15+
import pytest
1616

17-
@flaky
17+
18+
@pytest.mark.flaky
1819
def test_quickstart(capsys):
1920
import quickstart
2021

ml_engine/online_prediction/predict_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import json
1616
import socket
1717

18-
from flaky import flaky
1918
import pytest
2019

2120
import predict
@@ -42,29 +41,29 @@
4241
BYTESTRING = f.read()
4342

4443

45-
@flaky
44+
@pytest.mark.flaky
4645
def test_predict_json():
4746
result = predict.predict_json(
4847
PROJECT, MODEL, [JSON, JSON], version=JSON_VERSION)
4948
assert [EXPECTED_OUTPUT, EXPECTED_OUTPUT] == result
5049

5150

52-
@flaky
51+
@pytest.mark.flaky
5352
def test_predict_json_error():
5453
with pytest.raises(RuntimeError):
5554
predict.predict_json(
5655
PROJECT, MODEL, [{"foo": "bar"}], version=JSON_VERSION)
5756

5857

59-
@flaky
58+
@pytest.mark.flaky
6059
def test_census_example_to_bytes():
6160
import tensorflow as tf
6261
b = predict.census_to_example_bytes(JSON)
6362
assert tf.train.Example.FromString(b) == tf.train.Example.FromString(
6463
BYTESTRING)
6564

6665

67-
@flaky(max_runs=6)
66+
@pytest.mark.flaky(max_runs=6)
6867
def test_predict_examples():
6968
result = predict.predict_examples(
7069
PROJECT, MODEL, [BYTESTRING, BYTESTRING], version=EXAMPLES_VERSION)

monitoring/api/v3/api-client/list_resources_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import os
2424
import re
2525

26-
from flaky import flaky
2726
import googleapiclient.discovery
2827
import pytest
2928

@@ -38,7 +37,7 @@ def client():
3837
return googleapiclient.discovery.build('monitoring', 'v3')
3938

4039

41-
@flaky
40+
@pytest.mark.flaky
4241
def test_list_monitored_resources(client, capsys):
4342
PROJECT_RESOURCE = "projects/{}".format(PROJECT)
4443
list_resources.list_monitored_resource_descriptors(
@@ -49,7 +48,7 @@ def test_list_monitored_resources(client, capsys):
4948
assert regex.search(stdout) is not None
5049

5150

52-
@flaky
51+
@pytest.mark.flaky
5352
def test_list_metrics(client, capsys):
5453
PROJECT_RESOURCE = "projects/{}".format(PROJECT)
5554
list_resources.list_metric_descriptors(
@@ -60,7 +59,7 @@ def test_list_metrics(client, capsys):
6059
assert regex.search(stdout) is not None
6160

6261

63-
@flaky
62+
@pytest.mark.flaky
6463
def test_list_timeseries(client, capsys):
6564
PROJECT_RESOURCE = "projects/{}".format(PROJECT)
6665
list_resources.list_timeseries(

storage/api/customer_supplied_keys_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
import os
1515
import re
1616

17-
from flaky import flaky
17+
import pytest
1818

1919
from customer_supplied_keys import main
2020

2121
BUCKET = os.environ['CLOUD_STORAGE_BUCKET']
2222

2323

24-
@flaky
24+
@pytest.mark.flaky
2525
def test_main(capsys):
2626
main(BUCKET, __file__)
2727
out, err = capsys.readouterr()

translate/cloud-client/translate_v3_batch_translate_text_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def bucket():
3333
bucket.delete(force=True)
3434

3535

36+
@pytest.mark.flaky(max_runs=3, min_passes=1)
3637
def test_batch_translate_text(capsys, bucket):
3738
translate_v3_batch_translate_text.batch_translate_text(
3839
"gs://cloud-samples-data/translation/text.txt",

translate/cloud-client/translate_v3_batch_translate_text_with_glossary_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def bucket():
5252
bucket.delete(force=True)
5353

5454

55+
@pytest.mark.flaky(max_runs=3, min_passes=1)
5556
def test_batch_translate_text_with_glossary(capsys, bucket, glossary):
5657
translate_v3_batch_translate_text_with_glossary.batch_translate_text_with_glossary(
5758
"gs://cloud-samples-data/translation/text_with_glossary.txt",

translate/cloud-client/translate_v3_create_glossary_test.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,32 @@
1313
# limitations under the License.
1414

1515
import os
16+
import uuid
17+
18+
import pytest
19+
1620
import translate_v3_create_glossary
1721
import translate_v3_delete_glossary
18-
import uuid
1922

2023
PROJECT_ID = os.environ["GCLOUD_PROJECT"]
2124
GLOSSARY_INPUT_URI = "gs://cloud-samples-data/translation/glossary_ja.csv"
2225

2326

27+
@pytest.mark.flaky(max_runs=3, min_passes=1)
2428
def test_create_glossary(capsys):
25-
glossary_id = "test-{}".format(uuid.uuid4())
26-
translate_v3_create_glossary.create_glossary(
27-
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
28-
)
29-
out, _ = capsys.readouterr()
30-
# assert
31-
assert "Created:" in out
32-
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
33-
34-
# clean up after use
3529
try:
36-
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
37-
except Exception:
38-
pass
30+
glossary_id = "test-{}".format(uuid.uuid4())
31+
translate_v3_create_glossary.create_glossary(
32+
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
33+
)
34+
out, _ = capsys.readouterr()
35+
# assert
36+
assert "Created:" in out
37+
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
38+
finally:
39+
# clean up after use
40+
try:
41+
translate_v3_delete_glossary.delete_glossary(
42+
PROJECT_ID, glossary_id)
43+
except Exception:
44+
pass

translate/cloud-client/translate_v3_delete_glossary_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
# limitations under the License.
1414

1515
import os
16+
import uuid
17+
18+
import pytest
19+
1620
import translate_v3_create_glossary
1721
import translate_v3_delete_glossary
18-
import uuid
1922

2023
PROJECT_ID = os.environ["GCLOUD_PROJECT"]
2124
GLOSSARY_INPUT_URI = "gs://cloud-samples-data/translation/glossary_ja.csv"
2225

2326

27+
@pytest.mark.flaky(max_runs=3, min_passes=1)
2428
def test_delete_glossary(capsys):
2529
# setup
2630
glossary_id = "test-{}".format(uuid.uuid4())

vision/cloud-client/product_search/product_search_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515
import os
16-
from flaky import flaky
16+
17+
import pytest
1718

1819
from product_search import get_similar_products_file, get_similar_products_uri
1920

@@ -31,7 +32,7 @@
3132
FILTER = 'style=womens'
3233

3334

34-
@flaky(max_runs=5, min_passes=1)
35+
@pytest.mark.flaky(max_runs=5, min_passes=1)
3536
def test_get_similar_products_file(capsys):
3637
get_similar_products_file(
3738
PROJECT_ID, LOCATION, PRODUCT_SET_ID, PRODUCT_CATEGORY, FILE_PATH_1,

0 commit comments

Comments
 (0)