Pytest plugin (version 0.11.0) which splits the test suite into equally sized sub-suites based on test execution time. This enables faster and more balanced parallelization of tests in CI/CD environments. It is actively maintained with a consistent release cadence, often including support for new Python and Pytest versions.
pip install pytest-splitNo compatibility data collected yet for this library.
First, run pytest with the `--store-durations` flag to collect and save the execution times of your tests into a `.test_durations` file. This file should be committed to your repository. Then, use the `--splits N --group X` flags to divide your test suite into `N` groups and execute only the tests belonging to group `X`. This is typically used in CI/CD pipelines to parallelize test execution across multiple jobs.
Upgrade to a supported Python version (>=3.10) or pin pytest-split to an older version compatible with your Python environment.
Upgrade to pytest-split>=0.8.1 to ensure compatibility with updated pytest APIs.
If using randomization plugins, switch to the `least_duration` algorithm (`--splitting-algorithm least_duration`) or ensure a global random seed is computed and used for all groups via `--random-order-seed`.
Regularly re-run `pytest --store-durations` after significant changes to your test suite to update the `.test_durations` file and ensure optimal, balanced test splitting.
If you have custom tooling that processes the `.test_durations` file and are on an older version, be aware of potential format changes when upgrading. It's best to regenerate the file with `pytest --store-durations` after upgrading.
Ensure that `pytest` is invoked as a shell command (e.g., directly in the shell or via a dedicated shell script) rather than being placed within a Python file that is then executed by the Python interpreter.
Ensure pytest commands are executed directly in the shell (e.g., via `subprocess.run()` in Python scripts, or as a direct command in a Dockerfile/shell entrypoint) and are not parsed by the Python interpreter as Python code.
Ensure `pytest-split` is installed in the active Python environment where pytest is being run: `pip install pytest-split`.
When using `pytest-xdist` with `pytest-split`, use `--dist=loadfile` or `--dist=each` instead of `--dist=loadgroup`, for example: `pytest --split-tests 2 --splits 1 --dist=loadfile`.
To generate a new splits file, run `pytest --split-tests <NUM_SPLITS>` without `--splits`; if you intend to use an existing file, ensure it's present and correctly located or specified via `--splits-path`.
Use either `--split-tests <NUM_SPLITS>` to generate new split definitions, or `--splits <INDEX>` to run a specific split using previously generated data, but not both in the same command.
Ensure the value provided for `--splits` is a valid 0-based index (e.g., if `--split-tests 3` was used, valid indices are 0, 1, or 2).