|
1 | 1 | # Pytest-split |
| 2 | + |
| 3 | +[](https://travis-ci.org/jerry-git/pytest-split) |
| 4 | +[](https://pypi.python.org/pypi/pytest-split/) |
| 5 | +[](https://pypi.python.org/pypi/pytest-split/) |
| 6 | + |
| 7 | +Pytest plugin which splits the test suite to equally sized "sub suites" based on test execution time. |
| 8 | + |
| 9 | +## Motivation |
| 10 | +* 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. |
| 11 | +* [`pytest-test-groups`](https://pypi.org/project/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. |
| 12 | +* [`pytest-xdist`](https://pypi.org/project/pytest-xdist/) is great but it's not suitable for all use cases. |
| 13 | +For example, some test suites may be fragile considering the order in which the tests are executed. |
| 14 | +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). |
| 15 | +Additionally, `pytest-split` may be a better fit in some use cases considering distributed execution. |
| 16 | + |
| 17 | +## Installation |
| 18 | +``` |
| 19 | +pip install pytest-split |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | +First we have to store test durations from a complete test suite run. |
| 24 | +This produces .test_durations file which should be stored in the repo in order to have it available during future test runs. |
| 25 | +The file path is configurable via `--durations-path` CLI option. |
| 26 | +``` |
| 27 | +pytest --store-durations |
| 28 | +``` |
| 29 | + |
| 30 | +Then we can have as many splits as we want: |
| 31 | +``` |
| 32 | +pytest --splits 3 --group 1 |
| 33 | +pytest --splits 3 --group 2 |
| 34 | +pytest --splits 3 --group 3 |
| 35 | +``` |
| 36 | + |
| 37 | +Time goes by, new tests are added and old ones are removed/renamed during development. No worries! |
| 38 | +`pytest-split` assumes average test execution time (calculated based on the stored information) for every test which does not have duration information stored. |
| 39 | +Thus, there's no need to store durations after changing the test suite. |
| 40 | +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. |
0 commit comments