Skip to content

Commit 5d69334

Browse files
committed
test: if a test fails randomly, let it retry with @flaky
1 parent 65d686c commit 5d69334

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tests/helpers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
TypeVar, Union, cast,
2424
)
2525

26+
import flaky
2627
import pytest
2728

2829
from coverage import env
@@ -397,3 +398,12 @@ def __init__(self, options: Iterable[str]) -> None:
397398
def get_output(self) -> str:
398399
"""Get the output text from the `DebugControl`."""
399400
return self.io.getvalue()
401+
402+
403+
TestMethod = Callable[[Any], None]
404+
405+
def flaky_method(max_runs: int) -> Callable[[TestMethod], TestMethod]:
406+
"""flaky.flaky, but with type annotations."""
407+
def _decorator(fn: TestMethod) -> TestMethod:
408+
return cast(TestMethod, flaky.flaky(max_runs)(fn))
409+
return _decorator

tests/test_concurrency.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from tests import testenv
3232
from tests.coveragetest import CoverageTest
33+
from tests.helpers import flaky_method
3334

3435

3536
# These libraries aren't always available, we'll skip tests if they aren't.
@@ -317,6 +318,7 @@ def do():
317318
"""
318319
self.try_some_code(BUG_330, "eventlet", eventlet, "0\n")
319320

321+
@flaky_method(max_runs=3) # Sometimes a test fails due to inherent randomness. Try more times.
320322
def test_threads_with_gevent(self) -> None:
321323
self.make_file("both.py", """\
322324
import queue

0 commit comments

Comments
 (0)