Skip to main content

Pytest plugin to create CodSpeed benchmarks

Project description

pytest-codspeed

CI PyPi Version Python Version Discord CodSpeed Badge

Pytest plugin to create CodSpeed benchmarks


Documentation: https://codspeed.io/docs/reference/pytest-codspeed


Installation

pip install pytest-codspeed

Usage

Creating benchmarks

In a nutshell, pytest-codspeed offers two approaches to create performance benchmarks that integrate seamlessly with your existing test suite.

Use @pytest.mark.benchmark to measure entire test functions automatically:

import pytest
from statistics import median

@pytest.mark.benchmark
def test_median_performance():
    input = [1, 2, 3, 4, 5]
    output = sum(i**2 for i in input)
    assert output == 55

Since this measure the entire function, you might want to use the benchmark fixture for precise control over what code gets measured:

def test_mean_performance(benchmark):
    data = [1, 2, 3, 4, 5]
    # Only the function call is measured
    result = benchmark(lambda: sum(i**2 for i in data))
    assert result == 55

Check out the full documentation for more details.

Testing the benchmarks locally

If you want to run the benchmarks tests locally, you can use the --codspeed pytest flag:

$ pytest tests/ --codspeed
============================= test session starts ====================
platform darwin -- Python 3.14.0, pytest-7.4.4, pluggy-1.5.0
codspeed: 4.2.0 (enabled, mode: walltime, timer_resolution: 41.7ns)
rootdir: /home/user/codspeed-test, configfile: pytest.ini
plugins: codspeed-4.2.0
collected 1 items

tests/test_sum_squares.py .                                    [ 100%]

                         Benchmark Results
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓
┃     Benchmark   Time (best)  Rel. StdDev  Run time  Iters  ┃
┣━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━┫
┃test_sum_squares┃     1,873ns         4.8%     3.00s  66,930 ┃
┗━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━┛
=============================== 1 benchmarked ========================
=============================== 1 passed in 4.12s ====================

Running the benchmarks in your CI

You can use the CodSpeedHQ/action to run the benchmarks in Github Actions and upload the results to CodSpeed.

Here is an example of a GitHub Actions workflow that runs the benchmarks and reports the results to CodSpeed on every push to the main branch and every pull request:

name: CodSpeed

on:
  push:
    branches:
      - "main" # or "master"
  pull_request: # required to have reports on PRs
  # `workflow_dispatch` allows CodSpeed to trigger backtest
  # performance analysis in order to generate initial data.
  workflow_dispatch:

jobs:
  benchmarks:
    name: Run benchmarks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-python@v6
        with:
          python-version: "3.14"

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Run benchmarks
        uses: CodSpeedHQ/action@v4
        with:
          mode: simulation # or `walltime`
          token: ${{ secrets.CODSPEED_TOKEN }}
          run: pytest tests/ --codspeed

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_codspeed-4.4.0.tar.gz (201.1 kB view details)

Uploaded Source

Built Distributions

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

pytest_codspeed-4.4.0-py3-none-any.whl (203.8 kB view details)

Uploaded Python 3

pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (835.4 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (827.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (829.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (829.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (829.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (828.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (828.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (828.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (820.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file pytest_codspeed-4.4.0.tar.gz.

File metadata

  • Download URL: pytest_codspeed-4.4.0.tar.gz
  • Upload date:
  • Size: 201.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for pytest_codspeed-4.4.0.tar.gz
Algorithm Hash digest
SHA256 edb7c101d9c50439a42cf02cfa9c0ac92da618841636bbebf87c3fa54669442a
MD5 66d5b3f037bf00bd779174796eb27efd
BLAKE2b-256 52bc9070fdbfb479a0e92a12652a68875de157dc9be7dc4865a06a519e3a1877

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6aab2fa73523f538e7729c20ccf4a1e8e921324c9877a816b05334135950fd9
MD5 c8f16e5e954a2702ff801d86053984cc
BLAKE2b-256 99369e84323c6be426728e897133f8e9f3e65a90c26c137e190ca9b27bf304c3

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 33c38e0e797c74506004f231fc53eab0e412987de281755f714018334381aa3a
MD5 92fa4b5b7822eae8ea5921d4258010aa
BLAKE2b-256 7f57982ce8aa81089b285730dca8404c76af648af41e46d95012be54452913e6

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 56d5dd94dcb69460f916acb9c69865d0171b98acec3ce256645d0c0275b553d7
MD5 8c76dba1b172c1e56a40c8710d234514
BLAKE2b-256 d8f42cc5e10847aee4233690aa511df6b6f1c2c09f9d8ae506628a138f4ba201

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e258e6c3d5a8a02ae02a64831be3acd44c19210ffbf13321bdbb8c111c5c6fe4
MD5 da709c3585e19ca99155dae8a2172a12
BLAKE2b-256 8b7f3912bf6c2bcddb69189d23213f28e5bc058fd4c78fca15dd0010938154b0

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 413666266762f9cef1321ba971a9e127b97a1f1dad40ddfd2184c2bc5ac157f9
MD5 499d9a20dccd9437d4cb73f870a5e040
BLAKE2b-256 f28a24c7997d95f8bda081b8d4346750a5db0d9d8405183ee5cb9062f7381476

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 340dbb1cc5a21434e0e29bd68ab03c7dc7ad9bfde09d1980b7161352c4c2f048
MD5 907e0bc17445b2f2baed0f2747f0101e
BLAKE2b-256 e7660c3530c0dd9959b7f0930551b3de296db391040e5e8ad3e0cab917736980

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ee3e1964446011ca192eebf0350227df231a5b88af57e518f2a4328fc8ca5131
MD5 24672f210ad2c1af4b446fba4c140c8a
BLAKE2b-256 7853031793dab3a0edbbcbbd8755648ace0853f4cfb92a0e09e620f301f9ef5d

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 215170441e57bfcbefd179dfd86ccd54ed0ee235e0602a068ce4448b35f13cb2
MD5 600f6fee3fea6476b095141c6f397b20
BLAKE2b-256 1652beb46293d414d65163f8f3218aaa2f05e53bdc5cf64f24cc3843c31d3ca4

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6a5c1d51e7ca72ffe247c99b9a97a54191185e8f7a27528e2200d7416da2a68b
MD5 e7c14cd3db58a2f5f45cff7618a39fd1
BLAKE2b-256 3e704a401b37f80aaebbcbfb2803b0fab75331af554cd75755bc2059f7809bb4

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 06943110e7a8a4b54f4b13aaa3ff8db39caa02b2f61705916887649e36b9713a
MD5 2a6164aceb367cd65e6d24d154202499
BLAKE2b-256 de4a08a974ec4467258aa8e00d7ef3993c454ca265d6fe09bd6335135d818cb3

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 29b1bf8a36e18d11641a5e610e23a94036b04185e3099978d81a873a5bd3635c
MD5 ef92d924e7cdbfa4c186374fc49df772
BLAKE2b-256 9726b9a6620f52642ae6b7ba3f8c2dd3d85c636869a600553deabea98a7ae00e

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 83479a6719598d2910969a60cc410c7283c262c876422a9157dca2f2ab42fa1d
MD5 a907b9a2d4531f8e5512cc83f146b1e9
BLAKE2b-256 1c909f0cc2fc3245a3d3ee349fd521d6737ac26f79dfb94ed826086bb6ddd321

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f3ae6f4053042c3a9ae3b05416fb42253c5e514e89391eb25e9c9e3ac8de8677
MD5 67f0979303fb8abe602292a9b0fb9e24
BLAKE2b-256 b58d773162f910630c87ba5ea992ff1f267099ee55b3872f65bcbab5da9bc239

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 98524af4ddd6006ea064791bb15a43957d78fab040cb6f499ca73a369da373e6
MD5 0155a460eb823ceeab0ae72200c7385e
BLAKE2b-256 a004138a68faabeee981af4e849d2f22adb1af61fec1b5afc43e8c87a37886de

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pytest_codspeed-4.4.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4afa9455a9b198c5e898224c751182fcf53f67f11fb27c2c3346284da1baa018
MD5 0ccbe4890648c1fe6298feb81949f3a1
BLAKE2b-256 d1fa842f5a95379c02948ca7dd168bae0a6d6eef013af1657e7e44479d7a602b

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