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.13.0, pytest-7.4.4, pluggy-1.5.0
codspeed: 3.0.0 (enabled, mode: walltime, timer_resolution: 41.7ns)
rootdir: /home/user/codspeed-test, configfile: pytest.ini
plugins: codspeed-3.0.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@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"

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

      - name: Run benchmarks
        uses: CodSpeedHQ/action@v4
        with:
          mode: instrumentation   # 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.2.0.tar.gz (113.3 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.2.0-py3-none-any.whl (113.7 kB view details)

Uploaded Python 3

pytest_codspeed-4.2.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (256.7 kB view details)

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

pytest_codspeed-4.2.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (268.0 kB view details)

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

pytest_codspeed-4.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (251.1 kB view details)

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

pytest_codspeed-4.2.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (262.1 kB view details)

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

pytest_codspeed-4.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (251.0 kB view details)

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

pytest_codspeed-4.2.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (262.1 kB view details)

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

pytest_codspeed-4.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (251.1 kB view details)

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

pytest_codspeed-4.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (262.1 kB view details)

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

pytest_codspeed-4.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (250.8 kB view details)

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

pytest_codspeed-4.2.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (262.0 kB view details)

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

pytest_codspeed-4.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (250.8 kB view details)

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

pytest_codspeed-4.2.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (261.9 kB view details)

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

pytest_codspeed-4.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (250.8 kB view details)

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

pytest_codspeed-4.2.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (261.9 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for pytest_codspeed-4.2.0.tar.gz
Algorithm Hash digest
SHA256 04b5d0bc5a1851ba1504d46bf9d7dbb355222a69f2cd440d54295db721b331f7
MD5 6b0fc18c07596207513a4447e8a35199
BLAKE2b-256 e2e827fcbe6516a1c956614a4b61a7fccbf3791ea0b992e07416e8948184327d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e81bbb45c130874ef99aca97929d72682733527a49f84239ba575b5cb843bab0
MD5 65fb96162d4fdc85cf97c844c2e4d820
BLAKE2b-256 250e8cb71fd3ed4ed08c07aec1245aea7bc1b661ba55fd9c392db76f1978d453

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 748411c832147bfc85f805af78a1ab1684f52d08e14aabe22932bbe46c079a5f
MD5 038bc6591d49bf4aed287ef7d9d399ea
BLAKE2b-256 33864407341efb5dceb3e389635749ce1d670542d6ca148bd34f9d5334295faf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dbbb2d61b85bef8fc7e2193f723f9ac2db388a48259d981bbce96319043e9830
MD5 6174ebde27ee03574a9ed3c19e9aa27e
BLAKE2b-256 4b3948cf6afbca55bc7c8c93c3d4ae926a1068bcce3f0241709db19b078d5418

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a0ebd87f2a99467a1cfd8e83492c4712976e43d353ee0b5f71cbb057f1393aca
MD5 5f21fdf975eea39d1d8c2937025df9c0
BLAKE2b-256 f9148d9340d7dc0ae647991b28a396e16b3403e10def883cde90d6b663d3f7ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 50794dabea6ec90d4288904452051e2febace93e7edf4ca9f2bce8019dd8cd37
MD5 cb477c6ca2c646b1c4cb5f7ed7c4353f
BLAKE2b-256 0cfdeafd24db5652a94b4d00fe9b309b607de81add0f55f073afb68a378a24b6

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 684fcd9491d810ded653a8d38de4835daa2d001645f4a23942862950664273f8
MD5 3a01a50b9ed735f87fe97dd0715b9cb4
BLAKE2b-256 1d1cf1d2599784486879cf6579d8d94a3e22108f0e1f130033dab8feefd29249

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 72aab8278452a6d020798b9e4f82780966adb00f80d27a25d1274272c54630d5
MD5 bdfa18aee4a5e042d7cf1b3472bd199e
BLAKE2b-256 dedce864f45e994a50390ff49792256f1bdcbf42f170e3bc0470ee1a7d2403f3

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 309b4227f57fcbb9df21e889ea1ae191d0d1cd8b903b698fdb9ea0461dbf1dfe
MD5 7e363d7e71c01708da3ea041f8abf830
BLAKE2b-256 d246d6f345d7907bac6cbb6224bd697ecbc11cf7427acc9e843c3618f19e3476

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7d4fefbd4ae401e2c60f6be920a0be50eef0c3e4a1f0a1c83962efd45be38b39
MD5 d664db52a7b1faea41924e7cbab642d3
BLAKE2b-256 8104479905bd6653bc981c0554fcce6df52d7ae1594e1eefd53e6cf31810ec7f

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95aeb2479ca383f6b18e2cc9ebcd3b03ab184980a59a232aea6f370bbf59a1e3
MD5 d0b926650ec0021e38bcca36af5e219f
BLAKE2b-256 5f0c1f514c553db4ea5a69dfbe2706734129acd0eca8d5101ec16f1dd00dbc0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2de87bde9fbc6fd53f0fd21dcf2599c89e0b8948d49f9bad224edce51c47e26b
MD5 5a47f3dc7a0560096a6cbd893a9ed159
BLAKE2b-256 b92df0083a2f14ecf008d961d40439a71da0ae0d568e5f8dc2fccd3e8a2ab3e4

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 23a0c0fbf8bb4de93a3454fd9e5efcdca164c778aaef0a9da4f233d85cb7f5b8
MD5 6707bd8145550a0635d98d6e57c30187
BLAKE2b-256 7419ccc1a2fcd28357a8db08ba6b60f381832088a3850abc262c8e0b3406491a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 609828b03972966b75b9b7416fa2570c4a0f6124f67e02d35cd3658e64312a7b
MD5 80cdb96c78ea04514da15d7fa36a34f1
BLAKE2b-256 6cb8d599a466c50af3f04001877ae8b17c12b803f3b358235736b91a0769de0d

See more details on using hashes here.

File details

Details for the file pytest_codspeed-4.2.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.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0881a736285f33b9a8894da8fe8e1775aa1a4310226abe5d1f0329228efb680c
MD5 c8aa917003faa3548c9c35ac6ca2ae70
BLAKE2b-256 15ed442fb6a1832c2c9002653f24770873839b24c091bd2ed658090c7862c563

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_codspeed-4.2.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 238e17abe8f08d8747fa6c7acff34fefd3c40f17a56a7847ca13dc8d6e8c6009
MD5 4613da84a90c15ee8665e679dca9a9a9
BLAKE2b-256 fe60c395c19c14a1345d41ac3f7f0a9b372b666e88f9ba1f71988215174882bb

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