Skip to content

Commit 24e3136

Browse files
vdusekclaude
andcommitted
test: Add pytest-rerunfailures for integration tests
Add `pytest-rerunfailures` as a dev dependency and configure all integration tests to rerun up to 3 times on failure automatically. This helps handle occasional platform-related instabilities without manual test reruns. Uses `pytest_collection_modifyitems` hook to apply the flaky marker to all integration tests, avoiding the need to decorate each test individually. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 675eaf7 commit 24e3136

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ dev = [
7272
"pytest-asyncio<2.0.0",
7373
"pytest-cov<8.0.0",
7474
"pytest-httpserver<2.0.0",
75+
"pytest-rerunfailures<17.0.0",
7576
"pytest-timeout<3.0.0",
7677
"pytest-xdist<4.0.0",
7778
"pytest<9.0.0",

tests/integration/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from collections.abc import Callable
1717
from pathlib import Path
1818

19+
# Rerun all integration tests up to 3 times on failure, as the platform can be unstable.
20+
_INTEGRATION_TEST_RERUNS = 3
21+
1922
_TOKEN_ENV_VAR = 'APIFY_TEST_USER_API_TOKEN'
2023
_API_URL_ENV_VAR = 'APIFY_INTEGRATION_TESTS_API_URL'
2124

@@ -89,3 +92,10 @@ def _isolate_test_environment(prepare_test_env: Callable[[], None]) -> None:
8992
prepare_test_env: Fixture to prepare the environment before each test.
9093
"""
9194
prepare_test_env()
95+
96+
97+
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
98+
"""Add flaky marker with reruns to all integration tests."""
99+
flaky_marker = pytest.mark.flaky(reruns=_INTEGRATION_TEST_RERUNS)
100+
for item in items:
101+
item.add_marker(flaky_marker)

uv.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)