Skip to content

Commit 36906ee

Browse files
Takashi Matsuodanoscarmike
Takashi Matsuo
authored andcommitted
testing: replace @flaky with @pytest.mark.flaky [(#3496)](#3496)
* testing: replace @flaky with @pytest.mark.flaky * lint * mark few tests as flaky that involves LRO polling. * lint
1 parent ff6e0f5 commit 36906ee

4 files changed

+27
-15
lines changed

translation/samples/snippets/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",

translation/samples/snippets/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",

translation/samples/snippets/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

translation/samples/snippets/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())

0 commit comments

Comments
 (0)