Skip to content

Use flaky pytest fixture instead of decorator #2004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
)
from collections.abc import Iterable, Iterator

import flaky

import coverage
from coverage import env
from coverage.debug import DebugControl
Expand Down Expand Up @@ -390,15 +388,6 @@ def get_output(self) -> str:
return self.io.getvalue()


TestMethod = Callable[[Any], None]

def flaky_method(max_runs: int) -> Callable[[TestMethod], TestMethod]:
"""flaky.flaky, but with type annotations."""
def _decorator(fn: TestMethod) -> TestMethod:
return cast(TestMethod, flaky.flaky(max_runs)(fn))
return _decorator


def all_our_source_files() -> Iterator[tuple[Path, str]]:
"""Iterate over all of our own source files.

Expand Down
10 changes: 5 additions & 5 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from types import ModuleType
from collections.abc import Iterable

from flaky import flaky
import pytest

import coverage
Expand All @@ -30,7 +29,6 @@

from tests import testenv
from tests.coveragetest import CoverageTest
from tests.helpers import flaky_method


# These libraries aren't always available, we'll skip tests if they aren't.
Expand Down Expand Up @@ -318,7 +316,8 @@ def do():
"""
self.try_some_code(BUG_330, "eventlet", eventlet, "0\n")

@flaky_method(max_runs=3) # Sometimes a test fails due to inherent randomness. Try more times.
# Sometimes a test fails due to inherent randomness. Try more times.
@pytest.mark.flaky(max_runs=3)
def test_threads_with_gevent(self) -> None:
self.make_file("both.py", """\
import queue
Expand Down Expand Up @@ -452,7 +451,8 @@ def start_method_fixture(request: pytest.FixtureRequest) -> str:
return start_method


#@flaky(max_runs=30) # Sometimes a test fails due to inherent randomness. Try more times.
# Sometimes a test fails due to inherent randomness. Try more times.
#@pytest.mark.flaky(max_runs=30)
class MultiprocessingTest(CoverageTest):
"""Test support of the multiprocessing module."""

Expand Down Expand Up @@ -705,7 +705,7 @@ def random_load() -> None: # pragma: nested


@pytest.mark.skipif(env.WINDOWS, reason="SIGTERM doesn't work the same on Windows")
@flaky(max_runs=3) # Sometimes a test fails due to inherent randomness. Try more times.
@pytest.mark.flaky(max_runs=3) # Sometimes a test fails due to inherent randomness. Try more times.
class SigtermTest(CoverageTest):
"""Tests of our handling of SIGTERM."""

Expand Down
3 changes: 1 addition & 2 deletions tests/test_oddball.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import sys
import warnings

from flaky import flaky
import pytest

import coverage
Expand Down Expand Up @@ -167,7 +166,7 @@ class MemoryLeakTest(CoverageTest):
It may still fail occasionally, especially on PyPy.

"""
@flaky # type: ignore[misc]
@pytest.mark.flaky
@pytest.mark.skipif(not testenv.C_TRACER, reason="Only the C tracer has refcounting issues")
def test_for_leaks(self) -> None:
# Our original bad memory leak only happened on line numbers > 255, so
Expand Down
Loading