{"id":2728,"library":"pytest-retry","title":"pytest-retry","description":"pytest-retry is a plugin for Pytest that adds the ability to retry flaky tests, improving the consistency of test suite results. It currently supports Python 3.9+ and pytest 7.0.0+. The library maintains an active release cadence with regular updates.","status":"active","version":"1.7.0","language":"en","source_language":"en","source_url":"https://github.com/str0zzapreti/pytest-retry","tags":["pytest","testing","retry","flaky","ci"],"install":[{"cmd":"pip install pytest-retry","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core testing framework that this plugin extends. Requires pytest>=7.0.0.","package":"pytest","optional":false},{"reason":"Runtime environment. Requires Python>=3.9.","package":"python","optional":false}],"imports":[{"note":"The `pytest.mark.flaky` decorator is the primary way to mark individual tests for retrying. Direct imports from `pytest_retry` itself are generally not needed for basic usage, as pytest discovers the plugin automatically.","symbol":"pytest.mark.flaky","correct":"import pytest\n\n@pytest.mark.flaky(retries=3, delay=1)\ndef test_something_flaky():\n    # Test implementation\n    pass"}],"quickstart":{"code":"import pytest\nimport random\n\n@pytest.mark.flaky(retries=2, delay=0.5)\ndef test_sometimes_fails():\n    # This test has a 50% chance to fail, simulating flakiness.\n    # It will retry up to 2 times (3 attempts total) with a 0.5-second delay.\n    if random.random() < 0.5:\n        pytest.fail(\"Simulated intermittent failure\")\n    assert True\n\n# To run this test from your terminal:\n# pytest your_test_file.py\n# You can also set global retries:\n# pytest --retries 2 --retry-delay 0.5 your_test_file.py","lang":"python","description":"Mark a test function with `@pytest.mark.flaky(retries=N, delay=S)` to make it retry N additional times upon failure, with S seconds delay between attempts. Global retry settings can be configured via command-line arguments (`--retries N --retry-delay S`) or in `pytest.ini`/`pyproject.toml`."},"warnings":[{"fix":"Review tests using `@pytest.mark.flaky` and ensure explicit `retries` and `delay` arguments are set if global defaults should not apply, or adjust global defaults accordingly.","message":"Behavioral change in `flaky` mark argument fallback in version 1.4.0. Previously, arguments not specified in a `flaky` mark would fall back to default plugin values. From 1.4.0 onwards, unspecified arguments now fall back to your global defaults (e.g., from command line or `pytest.ini`) if specified, before falling back to plugin defaults.","severity":"breaking","affected_versions":"<1.4.0"},{"fix":"Upgrade to `pytest-retry` version 1.7.0 or higher, which includes a fix for this issue.","message":"Compatibility issues with `pytest-xdist` could lead to `ResourceWarning` messages, especially when using `n > 1` parallel workers.","severity":"gotcha","affected_versions":"<1.7.0"},{"fix":"Choose either `pytest-retry` or `pytest-rerunfailures` and ensure only one is installed. Use the correct arguments (`retries`, `delay` for `pytest-retry`; `reruns`, `reruns_delay` for `pytest-rerunfailures`) for the chosen plugin.","message":"There's another popular plugin, `pytest-rerunfailures`, which provides similar functionality but uses different command-line options (`--reruns`, `--reruns-delay`) and decorator arguments (`reruns`, `reruns_delay`). These two plugins are not compatible and should not be installed together.","severity":"gotcha","affected_versions":"all"},{"fix":"If using `pytest 8`, ensure `pytest-retry` is at version 1.6.2 or newer.","message":"Older versions of `pytest-retry` (prior to 1.6.2) had an 'Item instantiation error' when used with `pytest 8`.","severity":"gotcha","affected_versions":"<1.6.2 (when used with pytest 8)"},{"fix":"From version 1.7.0, use the `--retry-outcome` command-line option to specify a compatible outcome string (e.g., `pytest --retry-outcome rerun` for `pytest-html`).","message":"When using `pytest-retry` with other reporting plugins (e.g., `pytest-html`), the default 'retried' outcome name might cause compatibility issues.","severity":"gotcha","affected_versions":"<1.7.0"},{"fix":"For global configuration using `.ini` or `pyproject.toml`, upgrade to `pytest-retry` version 1.5.0 or newer. For older versions, use command-line arguments like `--retries` and `--retry-delay`.","message":"Global configuration of retries and delays via `pytest.ini` or `pyproject.toml` files was introduced in version 1.5.0. Prior versions only supported command-line arguments for global settings.","severity":"gotcha","affected_versions":"<1.5.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}