Skip to content

Commit

Permalink
testing: replace @flaky with @pytest.mark.flaky [(#3496)](#3496)
Browse files Browse the repository at this point in the history
* testing: replace @flaky with @pytest.mark.flaky

* lint

* mark few tests as flaky

that involves LRO polling.

* lint
  • Loading branch information
Takashi Matsuo authored and danoscarmike committed Jul 31, 2020
1 parent ff6e0f5 commit 36906ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def bucket():
bucket.delete(force=True)


@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_batch_translate_text(capsys, bucket):
translate_v3_batch_translate_text.batch_translate_text(
"gs://cloud-samples-data/translation/text.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def bucket():
bucket.delete(force=True)


@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_batch_translate_text_with_glossary(capsys, bucket, glossary):
translate_v3_batch_translate_text_with_glossary.batch_translate_text_with_glossary(
"gs://cloud-samples-data/translation/text_with_glossary.txt",
Expand Down
34 changes: 20 additions & 14 deletions translation/samples/snippets/translate_v3_create_glossary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,32 @@
# limitations under the License.

import os
import uuid

import pytest

import translate_v3_create_glossary
import translate_v3_delete_glossary
import uuid

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


@pytest.mark.flaky(max_runs=3, min_passes=1)
def test_create_glossary(capsys):
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
out, _ = capsys.readouterr()
# assert
assert "Created:" in out
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out

# clean up after use
try:
translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
except Exception:
pass
glossary_id = "test-{}".format(uuid.uuid4())
translate_v3_create_glossary.create_glossary(
PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
)
out, _ = capsys.readouterr()
# assert
assert "Created:" in out
assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
finally:
# clean up after use
try:
translate_v3_delete_glossary.delete_glossary(
PROJECT_ID, glossary_id)
except Exception:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
# limitations under the License.

import os
import uuid

import pytest

import translate_v3_create_glossary
import translate_v3_delete_glossary
import uuid

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


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

0 comments on commit 36906ee

Please sign in to comment.