Skip to main content

pytest-slowest-first

PyPI version Python versions CI status

Sort tests by their last duration, slowest first.


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features

  • Sort tests on consecutive runs by their last duration, slowest first.

  • Works with pytest-xdist by pre-assigning tests to workers based on their last duration.

Requirements

  • Python >= 3.10

  • pytest >= 7.0, < 9.2

  • pytest-xdist (optional)

Installation

You can install “pytest-slowest-first” via pip from PyPI:

$ pip install pytest-slowest-first

Usage

For best results, use this plugin with pytest-xdist to run tests in parallel. When used together, make sure to pass --dist=loadgroup to pytest to ensure that tests are distributed evenly across workers.

Other xdist schedulers keep their own distribution policy. Existing xdist_group markers keep their worker affinity with loadgroup. Durations recorded in parallel also apply to later serial runs.

pytest 9.2 changed test node IDs in a way that breaks grouping in pytest-xdist 3.8. Use pytest below 9.2 until pytest-xdist supports that change.

Example command line:

$ pytest --sf -n auto --dist=loadgroup

Contributing

Install uv, then sync the development environment from the lockfile:

$ uv sync --locked

Run tests, lint, and build distributions:

$ uv run --locked pytest tests
$ uv run --locked flake8 --max-line-length 100 pytest_slowest_first.py tests
$ uv run --locked ruff check .
$ uv run --locked ruff format --check .
$ uv build

Dependencies and package metadata live in pyproject.toml. Commit uv.lock after changing dependencies with uv add or uv lock. GitHub Actions runs on pull requests and pushes to main. Tests and lint use the locked environment on Linux and Windows with Python 3.10 through 3.14.

Releasing

Update the version in pyproject.toml, run uv lock, and merge the change to main. Push a matching version tag to release:

$ git tag -a v0.2.0 -m "Release 0.2.0"
$ git push origin v0.2.0

The release workflow verifies the tag matches the package version, runs checks, and builds the wheel and source archive. It creates a GitHub release with both files and publishes them to PyPI through trusted publishing.

Configure the PyPI project’s trusted publisher with owner klimkin, repository pytest-slowest-first, workflow release.yml, and environment pypi.

License

Distributed under the terms of the MIT license, “pytest-slowest-first” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for pytest-slowest-first 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-slowest-first 0.2.0
File Size Uploaded Provenance Actions
pytest_slowest_first-0.2.0.tar.gz 19.6 kB Without provenance Details for pytest_slowest_first-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-slowest-first 0.2.0
File Interpreter ABI Platform Actions
pytest_slowest_first-0.2.0-py3-none-any.whl Python 3 none any Details for pytest_slowest_first-0.2.0-py3-none-any.whl

Total release size: 25.2 kB

Release files / pytest_slowest_first-0.2.0.tar.gz

Download URL pytest_slowest_first-0.2.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
083efcb95f55a2352f5681eb84230102948a25604147c3501eeebc738e37181f
BLAKE2b-256 checksum
How to use checksums
7b1b9a35d71b9b729fc985e2918718920f6481f845134ffb37f55b610b6aa7f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / pytest_slowest_first-0.2.0-py3-none-any.whl

Download URL pytest_slowest_first-0.2.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ef807aabcb55103540bfedf4eb50631cee63e69b6a085f39dc29f9370da3a09
BLAKE2b-256 checksum
How to use checksums
95afe88c881ba07eb45a787c3dd8d85834cb8323c6f2bfaee79d1dd2760f53a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.3

Security for pytest-slowest-first 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page