Run first the slowest tests of previous run
Project description
![Python versions](https://img.shields.io/pypi/v/pytest-slow-first.svg?raw=True) ![Python versions](https://img.shields.io/pypi/pyversions/pytest-slow-first.svg?raw=True)
## What it does?
Sort tests by their duration on the last run. Making slow tests run first. </br> </hr>
## How can it make your suite run faster?
Before all, these benefits only appear when running this plugin alongside with [pytest-xdist](https://github.com/pytest-dev/pytest-xdist).
Taking this into acount, now imagine a suite with 6 tests. Each one takes some amount of time to run. Ex:
<img src=”./docs/assets/test_suite.png?raw=true” alt=”Alt text” title=”Optional title” style=”width: 60% !important;”>
By running this suite with Xdist with 2 workers, tests at default order, the load of each worker would be like:
<img src=”./docs/assets/only_xdist.png?raw=true” alt=”Alt text” title=”Optional title” style=”width: 70% !important;”>
The problem with this approath is that demanding tests very often will go to same worker.
When this happens, the total time spend running your suit will be longer that necessary, because, as you can se in the above image, there are workers hanging without any more tests to run.
This plugin will ensure that slowers tests run first and are evenly distributed between workers. Now the execution of the same suite will look like this:
<img src=”./docs/assets/xdist_and_slow_first.png?raw=true” alt=”Alt text” title=”Optional title” style=”width: 60% !important;”>
### How it works?
This plugin will save the duration of each of your tests in a file or wherever you want. In the next time you run it, tests will be sorted by time spend in the last run, making your whole suite take less time to complete.
</br> </hr>
### Running with pytest-slow-first plugin Finally, activate the plugin by passing –slow-first as paramter of pytest command:
`bash pytest tests --slow-first -n3 # using along side xdist `
</br> </hr>
THis plugin will save the duration of each of your tests in a file named pytest-slow-first.json in the current directory. You can change the location by setting the enviroment variable SLOW_FIRST_PATH to the path you want. Ex: export SLOW_FIRST_PATH=/tmp/pytest-slow-first.json pytest –slow-first
Installation
You can install “pytest-slow-first” via pip:
$ pip install pytest-slow-first
Contributing
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
License
Distributed under the terms of the MIT license, “pytest-slow-first” is free and open source software.
Issues
If you encounter any problems, please file an issue along with a detailed description.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-slow-first-1.0.0.tar.gz
.
File metadata
- Download URL: pytest-slow-first-1.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9dd33ef46b7680fd0a33a446163f09b82995a97442b90c5ebc2097de802c2a0 |
|
MD5 | 09146e928df17a639ce10be67a9da9f6 |
|
BLAKE2b-256 | c77d1414e69a5bf2f811f354196946e9b4041dc6ebd38f98f366bdcbcca4d1fe |
File details
Details for the file pytest_slow_first-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_slow_first-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d5e335e923f5cf179c309a21f438ad702e020cf4bcdeb8168d0e57dee7bbd1a |
|
MD5 | 6b5837225219d8d71bded1006678b811 |
|
BLAKE2b-256 | 207f361de0374641da442b57256961aaa704a0f68508bbfbb24bb57f911ef227 |