Skip to main content

Pytest plugin for splitting test suite based on test execution time

Project description

Pytest-split

Build Status PyPI version PyPI pyversions

Pytest plugin which splits the test suite to equally sized "sub suites" based on test execution time.

Motivation

  • Splitting the test suite is a prerequisite for parallelization (who does not want faster CI builds?). It's valuable to have sub suites which execution time is around the same.
  • pytest-test-groups is great but it does not take into account the execution time of sub suites which can lead to notably unbalanced execution times between the sub suites.
  • pytest-xdist is great but it's not suitable for all use cases. For example, some test suites may be fragile considering the order in which the tests are executed. This is of course a fundamental problem in the suite itself but sometimes it's not worth the effort to refactor, especially if the suite is huge (and smells a bit like legacy). Additionally, pytest-split may be a better fit in some use cases considering distributed execution.

Installation

pip install pytest-split

Usage

First we have to store test durations from a complete test suite run. This produces .test_durations file which should be stored in the repo in order to have it available during future test runs. The file path is configurable via --durations-path CLI option.

pytest --store-durations

Then we can have as many splits as we want:

pytest --splits 3 --group 1
pytest --splits 3 --group 2
pytest --splits 3 --group 3

Time goes by, new tests are added and old ones are removed/renamed during development. No worries! pytest-split assumes average test execution time (calculated based on the stored information) for every test which does not have duration information stored. Thus, there's no need to store durations after changing the test suite. However, when there are major changes in the suite compared to what's stored in .test_durations, it's recommended to update the duration information with --store-durations to ensure that the splitting is in balance.

Demo with GitHub Actions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-split-0.2.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_split-0.2.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest-split-0.2.1.tar.gz.

File metadata

  • Download URL: pytest-split-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.8.0-1033-azure

File hashes

Hashes for pytest-split-0.2.1.tar.gz
Algorithm Hash digest
SHA256 67a8a7a56891202390808e3642a242cd146cfbf0fe42f205ea9bfc0f748e7c98
MD5 fda36ae9d74ca2d6a960c56d986e061b
BLAKE2b-256 3acb6a4414492340ab3648fb93298367e9ff7808bb92029a42d4a74186f6f2a9

See more details on using hashes here.

File details

Details for the file pytest_split-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_split-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.8.0-1033-azure

File hashes

Hashes for pytest_split-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c9df1596f74ae184fa0147b681add08523c61264e7b801a1e6927eb3b00c021
MD5 f4fcc1339ce17418a02ffc06a651a98b
BLAKE2b-256 8da99c76f6b20c79af2f60efcfc794733139206b767e307c1b13b18081481b66

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page