{"id":4214,"library":"pytest-flakefinder","title":"pytest-flakefinder","description":"pytest-flakefinder is a plugin for the pytest testing framework that helps identify flaky tests by running them multiple times within a single pytest invocation. The current version, 1.1.0, was last released in October 2022 and is maintained by Dropbox, offering features to configure the number of runs and set a maximum execution time.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/dropbox/pytest-flakefinder","tags":["pytest","testing","flakiness","ci","plugin","developer-tools"],"install":[{"cmd":"pip install pytest-flakefinder","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"pytest-flakefinder is a plugin for pytest and requires it to function.","package":"pytest"},{"reason":"Recommended for parallel execution of flake runs, improving performance and exposing more timing-related flakes.","package":"pytest-xdist","optional":true}],"imports":[],"quickstart":{"code":"import random\n\ndef test_might_be_flaky():\n    # This test has a 30% chance of failing to simulate flakiness\n    if random.random() < 0.3:\n        assert False, \"This test failed flakily!\"\n    else:\n        assert True\n\n# To run all tests 100 times to find flakes:\n# pytest --flake-finder --flake-runs=100\n\n# To run tests with a maximum time limit of 5 minutes:\n# pytest --flake-finder --flake-max-minutes=5\n\n# Combine with pytest-xdist for parallel execution (requires prior installation of pytest-xdist):\n# pytest -n auto --flake-finder --flake-runs=100","lang":"python","description":"After installation, pytest-flakefinder integrates directly with the `pytest` command-line interface. You enable it with `--flake-finder` and can customize the number of repetitions with `--flake-runs` or set a time limit with `--flake-max-minutes`. Place the example code in a file named `test_example.py` and run the `pytest` commands from your terminal."},"warnings":[{"fix":"For larger test suites or higher flake counts, install `pytest-xdist` (`pip install pytest-xdist`) and run pytest with `-n auto` (e.g., `pytest -n auto --flake-finder`).","message":"Running tests many times with `--flake-runs` without parallelization (e.g., using `pytest-xdist`) can significantly increase execution time.","severity":"gotcha","affected_versions":"All"},{"fix":"Account for individual test run times when setting `--flake-max-minutes`. For strict test timeouts, consider `pytest-timeout` in conjunction with `pytest-flakefinder`.","message":"The `--flake-max-minutes` option will only skip tests that *start* after the timeout has been reached. It does not interrupt currently running tests.","severity":"gotcha","affected_versions":"All"},{"fix":"Once flakes are identified, investigate and fix the underlying causes (e.g., race conditions, external dependencies, state pollution). For automatic retries in CI, plugins like `pytest-rerunfailures` are often used instead.","message":"pytest-flakefinder is designed to *find* flakiness, not to *fix* or *mitigate* it during regular CI runs. Its purpose is diagnostic.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}