pytest-codspeed


Namepytest-codspeed JSON
Version 2.2.1 PyPI version JSON
download
home_page
SummaryPytest plugin to create CodSpeed benchmarks
upload_time2024-03-19 21:59:57
maintainer
docs_urlNone
author
requires_python>=3.7
licenseThe MIT License (MIT) Copyright (c) 2022 CodSpeed and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords benchmark codspeed performance pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<h1>pytest-codspeed</h1>

[![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)
[![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi)](https://pypi.org/project/pytest-codspeed)
![Python Version](https://img.shields.io/badge/python-3.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-informational.svg)
[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)

Pytest plugin to create CodSpeed benchmarks

</div>

## Requirements

**Python**: 3.7 and later

**pytest**: any recent version

## Installation

```shell
pip install pytest-codspeed
```

## Usage

### Creating benchmarks

Creating benchmarks with `pytest-codspeed` is compatible with the standard `pytest-benchmark` API. So if you already have benchmarks written with it, you can start using `pytest-codspeed` right away.

#### Marking a whole test function as a benchmark with `pytest.mark.benchmark`

```python
import pytest
from statistics import median

@pytest.mark.benchmark
def test_median_performance():
    return median([1, 2, 3, 4, 5])
```

#### Benchmarking selected lines of a test function with the `benchmark` fixture

```python
import pytest
from statistics import mean

def test_mean_performance(benchmark):
    # Precompute some data useful for the benchmark but that should not be
    # included in the benchmark time
    data = [1, 2, 3, 4, 5]

    # Benchmark the execution of the function
    benchmark(lambda: mean(data))


def test_mean_and_median_performance(benchmark):
    # Precompute some data useful for the benchmark but that should not be
    # included in the benchmark time
    data = [1, 2, 3, 4, 5]

    # Benchmark the execution of the function:
    # The `@benchmark` decorator will automatically call the function and
    # measure its execution
    @benchmark
    def bench():
        mean(data)
        median(data)
```

### Running benchmarks

#### Testing the benchmarks locally

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

```shell
pytest tests/ --codspeed
```

> **Note:** Running `pytest-codspeed` locally will not produce any performance reporting. It's only useful for making sure that your benchmarks are working as expected. If you want to get performance reporting, you should run the benchmarks in your CI.

#### In your CI

You can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run the benchmarks in Github Actions and upload the results to CodSpeed.

Example workflow:

```yaml
name: benchmarks

on:
  push:
    branches:
      - "main" # or "master"
  pull_request:

jobs:
  benchmarks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: "3.9"
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run benchmarks
        uses: CodSpeedHQ/action@v2
        with:
          token: ${{ secrets.CODSPEED_TOKEN }}
          run: pytest tests/ --codspeed
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-codspeed",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "benchmark,codspeed,performance,pytest",
    "author": "",
    "author_email": "Arthur Pastel <arthur@codspeed.io>",
    "download_url": "https://files.pythonhosted.org/packages/40/6a/ba0b067dba286443a04c9d32ff75ef3bc169617ee347d1a97972ada62665/pytest_codspeed-2.2.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n<h1>pytest-codspeed</h1>\n\n[![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)\n[![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi)](https://pypi.org/project/pytest-codspeed)\n![Python Version](https://img.shields.io/badge/python-3.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-informational.svg)\n[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)\n[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)\n\nPytest plugin to create CodSpeed benchmarks\n\n</div>\n\n## Requirements\n\n**Python**: 3.7 and later\n\n**pytest**: any recent version\n\n## Installation\n\n```shell\npip install pytest-codspeed\n```\n\n## Usage\n\n### Creating benchmarks\n\nCreating benchmarks with `pytest-codspeed` is compatible with the standard `pytest-benchmark` API. So if you already have benchmarks written with it, you can start using `pytest-codspeed` right away.\n\n#### Marking a whole test function as a benchmark with `pytest.mark.benchmark`\n\n```python\nimport pytest\nfrom statistics import median\n\n@pytest.mark.benchmark\ndef test_median_performance():\n    return median([1, 2, 3, 4, 5])\n```\n\n#### Benchmarking selected lines of a test function with the `benchmark` fixture\n\n```python\nimport pytest\nfrom statistics import mean\n\ndef test_mean_performance(benchmark):\n    # Precompute some data useful for the benchmark but that should not be\n    # included in the benchmark time\n    data = [1, 2, 3, 4, 5]\n\n    # Benchmark the execution of the function\n    benchmark(lambda: mean(data))\n\n\ndef test_mean_and_median_performance(benchmark):\n    # Precompute some data useful for the benchmark but that should not be\n    # included in the benchmark time\n    data = [1, 2, 3, 4, 5]\n\n    # Benchmark the execution of the function:\n    # The `@benchmark` decorator will automatically call the function and\n    # measure its execution\n    @benchmark\n    def bench():\n        mean(data)\n        median(data)\n```\n\n### Running benchmarks\n\n#### Testing the benchmarks locally\n\nIf you want to run only the benchmarks tests locally, you can use the `--codspeed` pytest flag:\n\n```shell\npytest tests/ --codspeed\n```\n\n> **Note:** Running `pytest-codspeed` locally will not produce any performance reporting. It's only useful for making sure that your benchmarks are working as expected. If you want to get performance reporting, you should run the benchmarks in your CI.\n\n#### In your CI\n\nYou can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run the benchmarks in Github Actions and upload the results to CodSpeed.\n\nExample workflow:\n\n```yaml\nname: benchmarks\n\non:\n  push:\n    branches:\n      - \"main\" # or \"master\"\n  pull_request:\n\njobs:\n  benchmarks:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v3\n      - uses: actions/setup-python@v3\n        with:\n          python-version: \"3.9\"\n      - name: Install dependencies\n        run: pip install -r requirements.txt\n      - name: Run benchmarks\n        uses: CodSpeedHQ/action@v2\n        with:\n          token: ${{ secrets.CODSPEED_TOKEN }}\n          run: pytest tests/ --codspeed\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2022 CodSpeed and contributors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Pytest plugin to create CodSpeed benchmarks",
    "version": "2.2.1",
    "project_urls": {
        "Documentation": "https://docs.codspeed.io/",
        "Homepage": "https://codspeed.io/",
        "Source": "https://github.com/CodSpeedHQ/pytest-codspeed"
    },
    "split_keywords": [
        "benchmark",
        "codspeed",
        "performance",
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "030be3541064afcf24ed54bcabfa6eb5f8083eb335d5c58c7b5b95bc31127f86",
                "md5": "5117f7e579491662bb21d1f52370b613",
                "sha256": "aad08033015f3e6c8c14c8bf0eca475921a9b088e92c98b626bf8af8f516471e"
            },
            "downloads": -1,
            "filename": "pytest_codspeed-2.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5117f7e579491662bb21d1f52370b613",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10126,
            "upload_time": "2024-03-19T21:59:55",
            "upload_time_iso_8601": "2024-03-19T21:59:55.388019Z",
            "url": "https://files.pythonhosted.org/packages/03/0b/e3541064afcf24ed54bcabfa6eb5f8083eb335d5c58c7b5b95bc31127f86/pytest_codspeed-2.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "406aba0b067dba286443a04c9d32ff75ef3bc169617ee347d1a97972ada62665",
                "md5": "ca8378a1e01faf63f77c00f47e14b029",
                "sha256": "0adc24baf01c64a6ca0a0b83b3cd704351708997e09ec086b7776c32227d4e0a"
            },
            "downloads": -1,
            "filename": "pytest_codspeed-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ca8378a1e01faf63f77c00f47e14b029",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9163,
            "upload_time": "2024-03-19T21:59:57",
            "upload_time_iso_8601": "2024-03-19T21:59:57.142906Z",
            "url": "https://files.pythonhosted.org/packages/40/6a/ba0b067dba286443a04c9d32ff75ef3bc169617ee347d1a97972ada62665/pytest_codspeed-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-19 21:59:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CodSpeedHQ",
    "github_project": "pytest-codspeed",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-codspeed"
}
        
Elapsed time: 0.34175s