pytest-codspeed


Namepytest-codspeed JSON
Version 2.2.0 PyPI version JSON
download
home_page
SummaryPytest plugin to create CodSpeed benchmarks
upload_time2023-09-01 12:54:27
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)
<a href="https://pypi.org/project/pytest-codspeed" target="_blank">
<img src="https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi" alt="Package version">
</a>
<img src="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" alt="python-3.7-3.8-3.9-3.10-3.11-3.12">
[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)

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@v1
        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/4e/2b/b0377084bede8a86b66c03118216e8f8f9912a414667d5ae610ae3942384/pytest_codspeed-2.2.0.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<a href=\"https://pypi.org/project/pytest-codspeed\" target=\"_blank\">\n<img src=\"https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi\" alt=\"Package version\">\n</a>\n<img src=\"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\" alt=\"python-3.7-3.8-3.9-3.10-3.11-3.12\">\n[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)\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@v1\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.0",
    "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": "89b8c79c4bfe9d961333a555953d7f0cbb02614bacddd767448a009638cecc50",
                "md5": "cf504852af4f05626fcd464a7e895a4e",
                "sha256": "5da48b842fc465926d122dd15bb86e86af5d9f0c53ec1b7c736e9a9aed558c13"
            },
            "downloads": -1,
            "filename": "pytest_codspeed-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf504852af4f05626fcd464a7e895a4e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10104,
            "upload_time": "2023-09-01T12:54:26",
            "upload_time_iso_8601": "2023-09-01T12:54:26.421496Z",
            "url": "https://files.pythonhosted.org/packages/89/b8/c79c4bfe9d961333a555953d7f0cbb02614bacddd767448a009638cecc50/pytest_codspeed-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e2bb0377084bede8a86b66c03118216e8f8f9912a414667d5ae610ae3942384",
                "md5": "5102a013d6e0954bdd7a6235b7e27feb",
                "sha256": "665003fc20117b64a98d16ffd1008f5bd6bf3b1e9af142b98c00abff7f626bbd"
            },
            "downloads": -1,
            "filename": "pytest_codspeed-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5102a013d6e0954bdd7a6235b7e27feb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9130,
            "upload_time": "2023-09-01T12:54:27",
            "upload_time_iso_8601": "2023-09-01T12:54:27.448667Z",
            "url": "https://files.pythonhosted.org/packages/4e/2b/b0377084bede8a86b66c03118216e8f8f9912a414667d5ae610ae3942384/pytest_codspeed-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-01 12:54:27",
    "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.11492s