Registry / testing / flaky

flaky

JSON →
library3.8.1pypypi✓ verified 52d ago

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.

testing
pip install flaky
Install & Compatibility
Where this runs
tested against v3.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flaky
from flaky import flaky
This imports the main decorator provided by the 'flaky' library.

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`).

import pytest from flaky import flaky import random @flaky(max_runs=3, min_passes=1) def test_something_that_sometimes_fails(): # Simulate a flaky condition that might pass on retry if random.random() < 0.6: # 60% chance of passing assert True else: assert False # To run this test, save it as a Python file (e.g., test_flaky_example.py) # and execute from your terminal: pytest test_flaky_example.py # The test will be run up to 3 times (max_runs) until it passes once (min_passes).
pytest --version
Debug
Known issues
breakingThe 'flaky' library's `@flaky` decorator can conflict with `@pytest.mark.flaky` provided by the 'pytest-rerunfailures' plugin if both are installed. It's recommended to choose one plugin for rerunning tests.
fix
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`.
affects: All versions where both plugins are active.
gotchaUsing the `--force-flaky` command-line option will apply flaky behavior (default `max_runs=1`, `min_passes=1`, implying 1 retry if not specified otherwise by `--max-runs` and `--min-passes`) to *all* tests in the run, overriding their deterministic nature. While useful for debugging, this can mask genuine failures.
fix
Use `--force-flaky` judiciously and be aware of its global impact. Explicitly mark individual tests with `@flaky(...)` for fine-grained control.
affects: All versions
gotchaThe 'flaky' plugin is compatible with `pytest-xdist` but explicitly does *not* work with `pytest-xdist`'s `--boxed` option. Using `--boxed` will result in unexpected behavior or errors.
fix
Avoid using the `--boxed` option when running tests with `flaky` and `pytest-xdist`.
affects: All versions
gotchaDoctests cannot be marked as flaky using this plugin. The `@flaky` decorator is intended for standard pytest functions.
fix
Do not attempt to apply the `@flaky` decorator to doctests. Consider converting doctests to standard pytest functions if flaky behavior is required.
affects: All versions
gotchaThe `max_runs` and `min_passes` parameters for the `@flaky` decorator control the retry logic. `max_runs` is the total number of attempts (initial run + retries), and `min_passes` is the number of successful attempts required. Misunderstanding these can lead to tests passing after fewer or more retries than intended.
fix
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flaky'
The 'flaky' library has not been installed in the current Python environment, or the environment where `pytest` is being run does not have access to the installed 'flaky' package.
fix
Ensure 'flaky' is installed using pip: `pip install flaky`
pytest: error: unrecognized arguments: --reruns
The `flaky` plugin (or `pytest-rerunfailures`) is not correctly installed or enabled in your pytest environment, leading pytest to not recognize the `--reruns` command-line option.
fix
Install the `flaky` plugin: `pip install flaky`. If already installed, ensure your pytest environment is correctly set up.
Doctests cannot be marked flaky.
The `flaky` plugin does not support marking doctests as flaky for automatic reruns. It is designed for standard pytest functions and methods.
fix
Convert doctests to regular pytest functions if flaky behavior is required, or refactor the flaky logic out of the doctest.
Flaky is incompatible with pytest-xdist's --boxed option.
Using `flaky` in conjunction with `pytest-xdist`'s `--boxed` option leads to an incompatibility, preventing tests from running correctly or causing unexpected behavior.
fix
Avoid using the `--boxed` option when running `pytest` with `flaky` and `pytest-xdist`. Consider alternative isolation strategies if boxing is critical.
Upgrade
Version history
3.8.1latest on PyPI
Audit
Dependencies
pytestrequiredFlaky is a plugin designed to extend pytest functionality, requiring pytest to be installed for operation.
Agent activity
15 hits · last 30 days
claudebot
4
seranking-bot
4
node
2
ahrefsbot
2
mj12bot
1
amazonbot
1
Resources