Flaky is a plugin for pytest that automatically reruns flaky tests. It helps improve test reliability by providing mechanisms to retry tests that exhibit intermittent or sporadic failures. Currently at version 3.8.1, the library maintains an active development pace with regular minor and patch releases.
pip install flakyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to mark a pytest function as flaky using the `@flaky` decorator. The test will automatically be re-run up to a specified number of times (`max_runs`) until it achieves a minimum number of passes (`min_passes`).
Decide which plugin best suits your needs and remove the other. If you must use `flaky`, ensure you import `from flaky import flaky` and use `@flaky`.
Use `--force-flaky` judiciously and be aware of its global impact. Explicitly mark individual tests with `@flaky(...)` for fine-grained control.
Avoid using the `--boxed` option when running tests with `flaky` and `pytest-xdist`.
Do not attempt to apply the `@flaky` decorator to doctests. Consider converting doctests to standard pytest functions if flaky behavior is required.
Always explicitly define `max_runs` and `min_passes` to match your desired retry behavior (e.g., `max_runs=3, min_passes=1` for up to 2 retries after 1 failure). Default behavior for `@flaky()` without arguments is generally one retry.
Ensure 'flaky' is installed using pip: `pip install flaky`
Install the `flaky` plugin: `pip install flaky`. If already installed, ensure your pytest environment is correctly set up.
Convert doctests to regular pytest functions if flaky behavior is required, or refactor the flaky logic out of the doctest.
Avoid using the `--boxed` option when running `pytest` with `flaky` and `pytest-xdist`. Consider alternative isolation strategies if boxing is critical.