Skip to content

Commit

Permalink
handle flaky translation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 29, 2024
1 parent 93102b2 commit 2cdd158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
from daras_ai_v2.send_email import pytest_outbox


def flaky(fn):
max_tries = 5

@wraps(fn)
def wrapper(*args, **kwargs):
for i in range(max_tries):
try:
return fn(*args, **kwargs)
except Exception:
if i == max_tries - 1:
raise

return wrapper


@pytest.fixture(scope="session")
def django_db_setup(django_db_setup, django_db_blocker):
with django_db_blocker.unblock():
Expand Down
2 changes: 2 additions & 0 deletions tests/test_translation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from conftest import flaky
from daras_ai_v2.asr import run_google_translate


Expand Down Expand Up @@ -48,6 +49,7 @@ def test_run_google_translate(threadpool_subtest):
threadpool_subtest(_test_run_google_translate_one, text, expected)


@flaky
def _test_run_google_translate_one(
text: str, expected: str, glossary_url=None, target_lang="en"
):
Expand Down

0 comments on commit 2cdd158

Please sign in to comment.