{"id":23159931,"url":"https://github.com/CodSpeedHQ/pytest-codspeed","last_synced_at":"2025-08-18T02:31:33.956Z","repository":{"id":62745493,"uuid":"535377158","full_name":"CodSpeedHQ/pytest-codspeed","owner":"CodSpeedHQ","description":"A pytest plugin to create benchmarks","archived":false,"fork":false,"pushed_at":"2025-07-24T09:43:56.000Z","size":293,"stargazers_count":97,"open_issues_count":12,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-24T13:31:58.282Z","etag":null,"topics":["benchmarking","codspeed","pytest","python"],"latest_commit_sha":null,"homepage":"https://codspeed.io/docs/reference/pytest-codspeed","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodSpeedHQ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-11T17:41:50.000Z","updated_at":"2025-07-24T09:44:00.000Z","dependencies_parsed_at":"2023-11-14T14:29:13.793Z","dependency_job_id":"9196fb24-24f1-4617-bd76-557d416ef8d1","html_url":"https://github.com/CodSpeedHQ/pytest-codspeed","commit_stats":{"total_commits":79,"total_committers":3,"mean_commits":"26.333333333333332","dds":"0.025316455696202556","last_synced_commit":"367ef470149485a8267e491f14a6c413d2821b03"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"purl":"pkg:github/CodSpeedHQ/pytest-codspeed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodSpeedHQ","download_url":"https://codeload.github.com/CodSpeedHQ/pytest-codspeed/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270933599,"owners_count":24670443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmarking","codspeed","pytest","python"],"created_at":"2024-12-17T23:00:31.644Z","updated_at":"2025-08-18T02:31:33.908Z","avatar_url":"https://github.com/CodSpeedHQ.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003epytest-codspeed\u003c/h1\u003e\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\u0026label=pypi)](https://pypi.org/project/pytest-codspeed)\n![Python Version](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-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\u003c/div\u003e\n\n---\n\n**Documentation**: https://codspeed.io/docs/reference/pytest-codspeed\n\n---\n\n## Installation\n\n```shell\npip install pytest-codspeed\n```\n\n## Usage\n\n### Creating benchmarks\n\nIn a nutshell, `pytest-codspeed` offers two approaches to create performance benchmarks that integrate seamlessly with your existing test suite.\n\nUse `@pytest.mark.benchmark` to measure entire test functions automatically:\n\n```python\nimport pytest\nfrom statistics import median\n\n@pytest.mark.benchmark\ndef test_median_performance():\n    input = [1, 2, 3, 4, 5]\n    output = sum(i**2 for i in input)\n    assert output == 55\n```\n\nSince this measure the entire function, you might want to use the `benchmark` fixture for precise control over what code gets measured:\n\n```python\ndef test_mean_performance(benchmark):\n    data = [1, 2, 3, 4, 5]\n    # Only the function call is measured\n    result = benchmark(lambda: sum(i**2 for i in data))\n    assert result == 55\n```\n\nCheck out the [full documentation](https://codspeed.io/docs/reference/pytest-codspeed) for more details.\n\n### Testing the benchmarks locally\n\nIf you want to run the benchmarks tests locally, you can use the `--codspeed` pytest flag:\n\n```sh\n$ pytest tests/ --codspeed\n============================= test session starts ====================\nplatform darwin -- Python 3.13.0, pytest-7.4.4, pluggy-1.5.0\ncodspeed: 3.0.0 (enabled, mode: walltime, timer_resolution: 41.7ns)\nrootdir: /home/user/codspeed-test, configfile: pytest.ini\nplugins: codspeed-3.0.0\ncollected 1 items\n\ntests/test_sum_squares.py .                                    [ 100%]\n\n                         Benchmark Results\n┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓\n┃     Benchmark  ┃ Time (best) ┃ Rel. StdDev ┃ Run time ┃ Iters  ┃\n┣━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━┫\n┃test_sum_squares┃     1,873ns ┃        4.8% ┃    3.00s ┃ 66,930 ┃\n┗━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━┛\n=============================== 1 benchmarked ========================\n=============================== 1 passed in 4.12s ====================\n```\n\n### Running the benchmarks 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\nHere 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:\n\n```yaml\nname: CodSpeed\n\non:\n  push:\n    branches:\n      - \"main\" # or \"master\"\n  pull_request: # required to have reports on PRs\n  # `workflow_dispatch` allows CodSpeed to trigger backtest\n  # performance analysis in order to generate initial data.\n  workflow_dispatch:\n\njobs:\n  benchmarks:\n    name: Run benchmarks\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-python@v5\n        with:\n          python-version: \"3.13\"\n\n      - name: Install dependencies\n        run: pip install -r requirements.txt\n\n      - name: Run benchmarks\n        uses: CodSpeedHQ/action@v3\n        with:\n          token: ${{ secrets.CODSPEED_TOKEN }}\n          run: pytest tests/ --codspeed\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodSpeedHQ%2Fpytest-codspeed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCodSpeedHQ%2Fpytest-codspeed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodSpeedHQ%2Fpytest-codspeed/lists"}