Flaky

3.8.1 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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

view raw JSON →