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.
pip install pytest-flakefinderNo compatibility data collected yet for this library.
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.
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`).
Account for individual test run times when setting `--flake-max-minutes`. For strict test timeouts, consider `pytest-timeout` in conjunction with `pytest-flakefinder`.
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.
Ensure pytest-flakefinder is installed in your active environment by running `pip install pytest-flakefinder`.
Remove the `import pytest_flakefinder` statement, as the plugin's functionality is accessed via pytest command-line options or `conftest.py` hooks.
Provide a valid integer for `--flake-runs` and a valid float for `--flake-max-exec-time`, for example: `pytest --flake-runs 3` or `pytest --flake-max-exec-time 1.5`.
Ensure both the option name (e.g., 'flakefinder-runs') and its corresponding value are provided, for example: `config.addinivalue_line('flakefinder-runs', '3')`.