pytest-codspeed 3.0.0b3__tar.gz → 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/PKG-INFO +21 -25
  2. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/README.md +4 -3
  3. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/pyproject.toml +41 -24
  4. pytest_codspeed-3.1.0/setup.cfg +4 -0
  5. pytest_codspeed-3.1.0/setup.py +53 -0
  6. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/__init__.py +2 -2
  7. pytest_codspeed-3.1.0/src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py +15 -0
  8. pytest_codspeed-3.1.0/src/pytest_codspeed/instruments/valgrind/_wrapper/build.py +19 -0
  9. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/walltime.py +21 -12
  10. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/plugin.py +15 -5
  11. pytest_codspeed-3.1.0/src/pytest_codspeed/py.typed +0 -0
  12. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/PKG-INFO +177 -0
  13. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/SOURCES.txt +26 -0
  14. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/dependency_links.txt +1 -0
  15. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/entry_points.txt +2 -0
  16. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/requires.txt +18 -0
  17. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/top_level.txt +1 -0
  18. pytest_codspeed-3.1.0/tests/test_pytest_plugin.py +300 -0
  19. pytest_codspeed-3.1.0/tests/test_pytest_plugin_cpu_instrumentation.py +118 -0
  20. pytest_codspeed-3.1.0/tests/test_pytest_plugin_walltime.py +37 -0
  21. pytest_codspeed-3.1.0/tests/test_utils.py +34 -0
  22. pytest_codspeed-3.0.0b3/.gitignore +0 -166
  23. pytest_codspeed-3.0.0b3/src/pytest_codspeed/instruments/valgrind/_wrapper/.gitignore +0 -2
  24. pytest_codspeed-3.0.0b3/src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py +0 -40
  25. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/LICENSE +0 -0
  26. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/__init__.py +0 -0
  27. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/__init__.py +0 -0
  28. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c +0 -0
  29. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h +0 -0
  30. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.pyi +0 -0
  31. {pytest_codspeed-3.0.0b3 → pytest_codspeed-3.1.0}/src/pytest_codspeed/utils.py +0 -0
@@ -1,10 +1,7 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.1
2
2
  Name: pytest-codspeed
3
- Version: 3.0.0b3
3
+ Version: 3.1.0
4
4
  Summary: Pytest plugin to create CodSpeed benchmarks
5
- Project-URL: Homepage, https://codspeed.io/
6
- Project-URL: Documentation, https://docs.codspeed.io/
7
- Project-URL: Source, https://github.com/CodSpeedHQ/pytest-codspeed
8
5
  Author-email: Arthur Pastel <arthur@codspeed.io>
9
6
  License: The MIT License (MIT)
10
7
 
@@ -27,15 +24,17 @@ License: The MIT License (MIT)
27
24
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
26
  THE SOFTWARE.
30
- License-File: LICENSE
31
- Keywords: benchmark,codspeed,performance,pytest
27
+
28
+ Project-URL: Homepage, https://codspeed.io/
29
+ Project-URL: Documentation, https://docs.codspeed.io/
30
+ Project-URL: Source, https://github.com/CodSpeedHQ/pytest-codspeed
31
+ Keywords: codspeed,benchmark,performance,pytest
32
32
  Classifier: Development Status :: 5 - Production/Stable
33
33
  Classifier: Framework :: Pytest
34
34
  Classifier: Intended Audience :: Developers
35
35
  Classifier: Intended Audience :: Information Technology
36
36
  Classifier: License :: OSI Approved :: MIT License
37
37
  Classifier: Programming Language :: Python :: 3
38
- Classifier: Programming Language :: Python :: 3.8
39
38
  Classifier: Programming Language :: Python :: 3.9
40
39
  Classifier: Programming Language :: Python :: 3.10
41
40
  Classifier: Programming Language :: Python :: 3.11
@@ -45,32 +44,28 @@ Classifier: Topic :: Software Development :: Testing
45
44
  Classifier: Topic :: System :: Benchmark
46
45
  Classifier: Topic :: Utilities
47
46
  Classifier: Typing :: Typed
48
- Requires-Python: >=3.8
47
+ Requires-Python: >=3.9
48
+ Description-Content-Type: text/markdown
49
49
  Requires-Dist: cffi>=1.17.1
50
- Requires-Dist: filelock>=3.12.2
51
- Requires-Dist: importlib-metadata>=8.5.0; python_version < '3.10'
52
50
  Requires-Dist: pytest>=3.8
53
51
  Requires-Dist: rich>=13.8.1
54
- Requires-Dist: setuptools; python_full_version >= '3.12.0'
55
- Provides-Extra: build
56
- Requires-Dist: semver>=3.0.2; extra == 'build'
57
- Provides-Extra: compat
58
- Requires-Dist: pytest-benchmark~=4.0.0; extra == 'compat'
59
- Requires-Dist: pytest-xdist~=3.6.1; extra == 'compat'
52
+ Requires-Dist: importlib-metadata>=8.5.0; python_version < "3.10"
60
53
  Provides-Extra: lint
61
- Requires-Dist: mypy~=1.11.2; extra == 'lint'
62
- Requires-Dist: ruff~=0.6.5; extra == 'lint'
54
+ Requires-Dist: mypy~=1.11.2; extra == "lint"
55
+ Requires-Dist: ruff~=0.6.5; extra == "lint"
56
+ Provides-Extra: compat
57
+ Requires-Dist: pytest-benchmark~=5.0.0; extra == "compat"
58
+ Requires-Dist: pytest-xdist~=3.6.1; extra == "compat"
63
59
  Provides-Extra: test
64
- Requires-Dist: pytest-cov~=4.0.0; extra == 'test'
65
- Requires-Dist: pytest~=7.0; extra == 'test'
66
- Description-Content-Type: text/markdown
60
+ Requires-Dist: pytest~=7.0; extra == "test"
61
+ Requires-Dist: pytest-cov~=4.0.0; extra == "test"
67
62
 
68
63
  <div align="center">
69
64
  <h1>pytest-codspeed</h1>
70
65
 
71
66
  [![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)
72
67
  [![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi)](https://pypi.org/project/pytest-codspeed)
73
- ![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)
68
+ ![Python Version](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)
74
69
  [![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
75
70
  [![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)
76
71
 
@@ -80,7 +75,7 @@ Pytest plugin to create CodSpeed benchmarks
80
75
 
81
76
  ## Requirements
82
77
 
83
- **Python**: 3.8 and later
78
+ **Python**: 3.9 and later
84
79
 
85
80
  **pytest**: any recent version
86
81
 
@@ -155,7 +150,7 @@ You can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run
155
150
  Example workflow:
156
151
 
157
152
  ```yaml
158
- name: benchmarks
153
+ name: CodSpeed
159
154
 
160
155
  on:
161
156
  push:
@@ -165,6 +160,7 @@ on:
165
160
 
166
161
  jobs:
167
162
  benchmarks:
163
+ name: Run benchmarks
168
164
  runs-on: ubuntu-latest
169
165
  steps:
170
166
  - uses: actions/checkout@v4
@@ -3,7 +3,7 @@
3
3
 
4
4
  [![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)
5
5
  [![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi)](https://pypi.org/project/pytest-codspeed)
6
- ![Python Version](https://img.shields.io/badge/python-3.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)
6
+ ![Python Version](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)
7
7
  [![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
8
8
  [![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)
9
9
 
@@ -13,7 +13,7 @@ Pytest plugin to create CodSpeed benchmarks
13
13
 
14
14
  ## Requirements
15
15
 
16
- **Python**: 3.8 and later
16
+ **Python**: 3.9 and later
17
17
 
18
18
  **pytest**: any recent version
19
19
 
@@ -88,7 +88,7 @@ You can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run
88
88
  Example workflow:
89
89
 
90
90
  ```yaml
91
- name: benchmarks
91
+ name: CodSpeed
92
92
 
93
93
  on:
94
94
  push:
@@ -98,6 +98,7 @@ on:
98
98
 
99
99
  jobs:
100
100
  benchmarks:
101
+ name: Run benchmarks
101
102
  runs-on: ubuntu-latest
102
103
  steps:
103
104
  - uses: actions/checkout@v4
@@ -1,7 +1,3 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
1
  [project.urls]
6
2
  Homepage = "https://codspeed.io/"
7
3
  Documentation = "https://docs.codspeed.io/"
@@ -13,7 +9,7 @@ dynamic = ["version"]
13
9
  description = "Pytest plugin to create CodSpeed benchmarks"
14
10
  readme = "README.md"
15
11
  license = { file = "LICENSE" }
16
- requires-python = ">=3.8"
12
+ requires-python = ">=3.9"
17
13
  authors = [{ name = "Arthur Pastel", email = "arthur@codspeed.io" }]
18
14
  keywords = ["codspeed", "benchmark", "performance", "pytest"]
19
15
  classifiers = [
@@ -23,7 +19,6 @@ classifiers = [
23
19
  "Intended Audience :: Information Technology",
24
20
  "License :: OSI Approved :: MIT License",
25
21
  "Programming Language :: Python :: 3",
26
- "Programming Language :: Python :: 3.8",
27
22
  "Programming Language :: Python :: 3.9",
28
23
  "Programming Language :: Python :: 3.10",
29
24
  "Programming Language :: Python :: 3.11",
@@ -36,43 +31,65 @@ classifiers = [
36
31
  ]
37
32
  dependencies = [
38
33
  "cffi >= 1.17.1",
39
- # cffi doesn't automatically install setuptools with python 3.12+
40
- # cf https://github.com/python-cffi/cffi/releases/tag/v1.16.0
41
- "setuptools; python_full_version >= '3.12.0'",
42
34
  "pytest>=3.8",
43
- "filelock >= 3.12.2",
44
35
  "rich>=13.8.1",
45
36
  "importlib-metadata>=8.5.0; python_version < '3.10'",
46
37
  ]
47
38
 
48
39
  [project.optional-dependencies]
49
- build = ["semver>=3.0.2"]
50
40
  lint = ["mypy ~= 1.11.2", "ruff ~= 0.6.5"]
51
41
  compat = [
52
- "pytest-benchmark ~= 4.0.0",
42
+ "pytest-benchmark ~= 5.0.0",
53
43
  "pytest-xdist ~= 3.6.1",
54
44
  # "pytest-speed>=0.3.5",
55
45
  ]
56
46
  test = ["pytest ~= 7.0", "pytest-cov ~= 4.0.0"]
47
+
57
48
  [project.entry-points]
58
49
  pytest11 = { codspeed = "pytest_codspeed.plugin" }
59
50
 
60
- [tool.hatch.envs.default]
61
- python = "3.11"
62
- features = ["lint", "test", "compat"]
51
+ [build-system]
52
+ requires = ["setuptools >= 61", "cffi >= 1.17.1"]
53
+ build-backend = "setuptools.build_meta"
54
+
55
+ [tool.setuptools]
56
+ license-files = [] # Workaround of https://github.com/astral-sh/uv/issues/9513
63
57
 
64
- [tool.hatch.envs.test]
65
- features = ["test"]
58
+ [tool.setuptools.dynamic]
59
+ version = { attr = "pytest_codspeed.__version__" }
66
60
 
67
- [[tool.hatch.envs.test.matrix]]
68
- python = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
69
- features = ["compat", "test"]
70
61
 
71
- [tool.hatch.version]
72
- path = "src/pytest_codspeed/__init__.py"
62
+ [tool.bumpver]
63
+ current_version = "3.1.0"
64
+ version_pattern = "MAJOR.MINOR.PATCH[-TAG]"
65
+ commit_message = "Release v{new_version} 🚀"
66
+ tag_message = "Release v{new_version} 🚀"
67
+ tag_scope = "default"
68
+ allow_dirty = false
69
+ pre_commit_hook = "./scripts/pre-release.sh"
70
+ post_commit_hook = "./scripts/post-release.sh"
71
+ commit = true
72
+ tag = false
73
+ push = false
74
+
75
+
76
+ [tool.bumpver.file_patterns]
77
+ "pyproject.toml" = ['current_version = "{version}"']
78
+ "src/pytest_codspeed/__init__.py" = [
79
+ '__version__ = "{pep440_version}"',
80
+ '__semver_version__ = "{version}"',
81
+ ]
82
+
83
+ [tool.cibuildwheel]
84
+ build = "cp*manylinux*"
85
+ test-extras = ["build", "test", "compat"]
86
+ test-command = "pytest -v --ignore={project}/tests/benchmarks {project}/tests"
73
87
 
74
- [tool.hatch.build.targets.sdist]
75
- include = ["/src"]
88
+ [tool.cibuildwheel.linux]
89
+ environment = { PYTEST_CODSPEED_FORCE_EXTENSION_BUILD = "1", PYTEST_CODSPEED_FORCE_VALGRIND_TESTS = "1" }
90
+ manylinux-x86_64-image = "manylinux_2_28"
91
+ manylinux-aarch64-image = "manylinux_2_28"
92
+ before-all = "yum -y install valgrind-devel"
76
93
 
77
94
  [tool.mypy]
78
95
  python_version = "3.12"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,53 @@
1
+ import importlib.util
2
+ import os
3
+ import platform
4
+ from pathlib import Path
5
+
6
+ from setuptools import setup
7
+
8
+ build_path = (
9
+ Path(__file__).parent / "src/pytest_codspeed/instruments/valgrind/_wrapper/build.py"
10
+ )
11
+
12
+ spec = importlib.util.spec_from_file_location("build", build_path)
13
+ assert spec is not None, "The spec should be initialized"
14
+ build = importlib.util.module_from_spec(spec)
15
+ assert spec.loader is not None, "The loader should be initialized"
16
+ spec.loader.exec_module(build)
17
+
18
+ system = platform.system()
19
+ current_arch = platform.machine()
20
+
21
+ print(f"System: {system} ({current_arch})")
22
+
23
+ IS_EXTENSION_BUILDABLE = system == "Linux" and current_arch in [
24
+ "x86_64",
25
+ "aarch64",
26
+ ]
27
+
28
+ IS_EXTENSION_REQUIRED = (
29
+ os.environ.get("PYTEST_CODSPEED_FORCE_EXTENSION_BUILD") is not None
30
+ )
31
+ if IS_EXTENSION_REQUIRED and not IS_EXTENSION_BUILDABLE:
32
+ raise ValueError(
33
+ "The extension is required but the current platform is not supported"
34
+ )
35
+
36
+
37
+ ffi_extension = build.ffibuilder.distutils_extension()
38
+ ffi_extension.optional = not IS_EXTENSION_REQUIRED
39
+
40
+ print(
41
+ "CodSpeed native extension is "
42
+ + ("required" if IS_EXTENSION_REQUIRED else "optional")
43
+ )
44
+
45
+ setup(
46
+ package_data={
47
+ "pytest_codspeed": [
48
+ "instruments/valgrind/_wrapper/*.h",
49
+ "instruments/valgrind/_wrapper/*.c",
50
+ ]
51
+ },
52
+ ext_modules=[ffi_extension] if IS_EXTENSION_BUILDABLE else [],
53
+ )
@@ -1,6 +1,6 @@
1
- __version__ = "3.0.0b3"
1
+ __version__ = "3.1.0"
2
2
  # We also have the semver version since __version__ is not semver compliant
3
- __semver_version__ = "3.0.0-b3"
3
+ __semver_version__ = "3.1.0"
4
4
 
5
5
  from .plugin import BenchmarkFixture
6
6
 
@@ -0,0 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from .wrapper import lib as LibType
7
+
8
+
9
+ def get_lib() -> LibType:
10
+ try:
11
+ from .dist_callgrind_wrapper import lib # type: ignore
12
+
13
+ return lib
14
+ except Exception as e:
15
+ raise Exception("Failed to get a compiled wrapper") from e
@@ -0,0 +1,19 @@
1
+ from pathlib import Path
2
+
3
+ from cffi import FFI # type: ignore
4
+
5
+ wrapper_dir = Path(__file__).parent
6
+
7
+ ffibuilder = FFI()
8
+
9
+ ffibuilder.cdef((wrapper_dir / "wrapper.h").read_text())
10
+
11
+ ffibuilder.set_source(
12
+ "pytest_codspeed.instruments.valgrind._wrapper.dist_callgrind_wrapper",
13
+ '#include "wrapper.h"',
14
+ sources=["src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c"],
15
+ include_dirs=[str(wrapper_dir)],
16
+ )
17
+
18
+ if __name__ == "__main__":
19
+ ffibuilder.compile(verbose=True)
@@ -7,6 +7,7 @@ from time import get_clock_info, perf_counter_ns
7
7
  from typing import TYPE_CHECKING
8
8
 
9
9
  from rich.console import Console
10
+ from rich.markup import escape
10
11
  from rich.table import Table
11
12
  from rich.text import Text
12
13
 
@@ -54,15 +55,14 @@ class BenchmarkStats:
54
55
  mean_ns: float
55
56
  stdev_ns: float
56
57
 
57
- lower_fence_ns: float
58
58
  q1_ns: float
59
59
  median_ns: float
60
60
  q3_ns: float
61
- upper_fence_ns: float
62
61
 
63
62
  rounds: int
64
63
  total_time: float
65
- outlier_rounds: int
64
+ iqr_outlier_rounds: int
65
+ stdev_outlier_rounds: int
66
66
  iter_per_round: int
67
67
  warmup_iters: int
68
68
 
@@ -78,12 +78,22 @@ class BenchmarkStats:
78
78
  ) -> BenchmarkStats:
79
79
  stdev_ns = stdev(times_ns) if len(times_ns) > 1 else 0
80
80
  mean_ns = mean(times_ns)
81
- q1_ns, median_ns, q3_ns = quantiles(times_ns, n=4)
81
+ if len(times_ns) > 1:
82
+ q1_ns, median_ns, q3_ns = quantiles(times_ns, n=4)
83
+ else:
84
+ q1_ns, median_ns, q3_ns = (
85
+ mean_ns,
86
+ mean_ns,
87
+ mean_ns,
88
+ )
82
89
  iqr_ns = q3_ns - q1_ns
83
- lower_fence_ns = q1_ns - 1.5 * iqr_ns
84
- upper_fence_ns = q3_ns + 1.5 * iqr_ns
85
- outliers_rounds = sum(
86
- 1 for t in times_ns if t < lower_fence_ns or t > upper_fence_ns
90
+ iqr_outlier_rounds = sum(
91
+ 1 for t in times_ns if t < q1_ns - 1.5 * iqr_ns or t > q3_ns + 1.5 * iqr_ns
92
+ )
93
+ stdev_outlier_rounds = sum(
94
+ 1
95
+ for t in times_ns
96
+ if t < mean_ns - 3 * stdev_ns or t > mean_ns + 3 * stdev_ns
87
97
  )
88
98
 
89
99
  return cls(
@@ -91,14 +101,13 @@ class BenchmarkStats:
91
101
  max_ns=max(times_ns),
92
102
  stdev_ns=stdev_ns,
93
103
  mean_ns=mean_ns,
94
- lower_fence_ns=lower_fence_ns,
95
104
  q1_ns=q1_ns,
96
105
  median_ns=median_ns,
97
106
  q3_ns=q3_ns,
98
- upper_fence_ns=upper_fence_ns,
99
107
  rounds=rounds,
100
108
  total_time=total_time,
101
- outlier_rounds=outliers_rounds,
109
+ iqr_outlier_rounds=iqr_outlier_rounds,
110
+ stdev_outlier_rounds=stdev_outlier_rounds,
102
111
  iter_per_round=iter_per_round,
103
112
  warmup_iters=warmup_iters,
104
113
  )
@@ -235,7 +244,7 @@ class WallTimeInstrument(Instrument):
235
244
  if rsd > 0.1:
236
245
  rsd_text.stylize("red bold")
237
246
  table.add_row(
238
- bench.name,
247
+ escape(bench.name),
239
248
  f"{bench.stats.min_ns/bench.stats.iter_per_round:,.0f}ns",
240
249
  rsd_text,
241
250
  f"{bench.stats.total_time:,.2f}s",
@@ -261,17 +261,15 @@ def _measure(
261
261
  ) -> T:
262
262
  is_gc_enabled = gc.isenabled()
263
263
  if is_gc_enabled:
264
- pass
265
- # gc.collect()
266
- # gc.disable()
264
+ gc.collect()
265
+ gc.disable()
267
266
  try:
268
267
  uri, name = get_git_relative_uri_and_name(nodeid, config.rootpath)
269
268
  return plugin.instrument.measure(name, uri, fn, *args, **kwargs)
270
269
  finally:
271
270
  # Ensure GC is re-enabled even if the test failed
272
271
  if is_gc_enabled:
273
- pass
274
- # gc.enable()
272
+ gc.enable()
275
273
 
276
274
 
277
275
  def wrap_runtest(
@@ -322,6 +320,18 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus):
322
320
  class BenchmarkFixture:
323
321
  """The fixture that can be used to benchmark a function."""
324
322
 
323
+ @property # type: ignore
324
+ def __class__(self):
325
+ # Bypass the pytest-benchmark fixture class check
326
+ # https://github.com/ionelmc/pytest-benchmark/commit/d6511e3474931feb4e862948128e0c389acfceec
327
+ if IS_PYTEST_BENCHMARK_INSTALLED:
328
+ from pytest_benchmark.fixture import (
329
+ BenchmarkFixture as PytestBenchmarkFixture,
330
+ )
331
+
332
+ return PytestBenchmarkFixture
333
+ return BenchmarkFixture
334
+
325
335
  def __init__(self, request: pytest.FixtureRequest):
326
336
  self.extra_info: dict = {}
327
337
 
File without changes
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.1
2
+ Name: pytest-codspeed
3
+ Version: 3.1.0
4
+ Summary: Pytest plugin to create CodSpeed benchmarks
5
+ Author-email: Arthur Pastel <arthur@codspeed.io>
6
+ License: The MIT License (MIT)
7
+
8
+ Copyright (c) 2022 CodSpeed and contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://codspeed.io/
29
+ Project-URL: Documentation, https://docs.codspeed.io/
30
+ Project-URL: Source, https://github.com/CodSpeedHQ/pytest-codspeed
31
+ Keywords: codspeed,benchmark,performance,pytest
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Framework :: Pytest
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Intended Audience :: Information Technology
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Topic :: Software Development :: Testing
44
+ Classifier: Topic :: System :: Benchmark
45
+ Classifier: Topic :: Utilities
46
+ Classifier: Typing :: Typed
47
+ Requires-Python: >=3.9
48
+ Description-Content-Type: text/markdown
49
+ Requires-Dist: cffi>=1.17.1
50
+ Requires-Dist: pytest>=3.8
51
+ Requires-Dist: rich>=13.8.1
52
+ Requires-Dist: importlib-metadata>=8.5.0; python_version < "3.10"
53
+ Provides-Extra: lint
54
+ Requires-Dist: mypy~=1.11.2; extra == "lint"
55
+ Requires-Dist: ruff~=0.6.5; extra == "lint"
56
+ Provides-Extra: compat
57
+ Requires-Dist: pytest-benchmark~=5.0.0; extra == "compat"
58
+ Requires-Dist: pytest-xdist~=3.6.1; extra == "compat"
59
+ Provides-Extra: test
60
+ Requires-Dist: pytest~=7.0; extra == "test"
61
+ Requires-Dist: pytest-cov~=4.0.0; extra == "test"
62
+
63
+ <div align="center">
64
+ <h1>pytest-codspeed</h1>
65
+
66
+ [![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)
67
+ [![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058&label=pypi)](https://pypi.org/project/pytest-codspeed)
68
+ ![Python Version](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)
69
+ [![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)
70
+ [![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)
71
+
72
+ Pytest plugin to create CodSpeed benchmarks
73
+
74
+ </div>
75
+
76
+ ## Requirements
77
+
78
+ **Python**: 3.9 and later
79
+
80
+ **pytest**: any recent version
81
+
82
+ ## Installation
83
+
84
+ ```shell
85
+ pip install pytest-codspeed
86
+ ```
87
+
88
+ ## Usage
89
+
90
+ ### Creating benchmarks
91
+
92
+ 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.
93
+
94
+ #### Marking a whole test function as a benchmark with `pytest.mark.benchmark`
95
+
96
+ ```python
97
+ import pytest
98
+ from statistics import median
99
+
100
+ @pytest.mark.benchmark
101
+ def test_median_performance():
102
+ return median([1, 2, 3, 4, 5])
103
+ ```
104
+
105
+ #### Benchmarking selected lines of a test function with the `benchmark` fixture
106
+
107
+ ```python
108
+ import pytest
109
+ from statistics import mean
110
+
111
+ def test_mean_performance(benchmark):
112
+ # Precompute some data useful for the benchmark but that should not be
113
+ # included in the benchmark time
114
+ data = [1, 2, 3, 4, 5]
115
+
116
+ # Benchmark the execution of the function
117
+ benchmark(lambda: mean(data))
118
+
119
+
120
+ def test_mean_and_median_performance(benchmark):
121
+ # Precompute some data useful for the benchmark but that should not be
122
+ # included in the benchmark time
123
+ data = [1, 2, 3, 4, 5]
124
+
125
+ # Benchmark the execution of the function:
126
+ # The `@benchmark` decorator will automatically call the function and
127
+ # measure its execution
128
+ @benchmark
129
+ def bench():
130
+ mean(data)
131
+ median(data)
132
+ ```
133
+
134
+ ### Running benchmarks
135
+
136
+ #### Testing the benchmarks locally
137
+
138
+ If you want to run only the benchmarks tests locally, you can use the `--codspeed` pytest flag:
139
+
140
+ ```shell
141
+ pytest tests/ --codspeed
142
+ ```
143
+
144
+ > **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.
145
+
146
+ #### In your CI
147
+
148
+ You can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run the benchmarks in Github Actions and upload the results to CodSpeed.
149
+
150
+ Example workflow:
151
+
152
+ ```yaml
153
+ name: CodSpeed
154
+
155
+ on:
156
+ push:
157
+ branches:
158
+ - "main" # or "master"
159
+ pull_request:
160
+
161
+ jobs:
162
+ benchmarks:
163
+ name: Run benchmarks
164
+ runs-on: ubuntu-latest
165
+ steps:
166
+ - uses: actions/checkout@v4
167
+ - uses: actions/setup-python@v5
168
+ with:
169
+ python-version: "3.12"
170
+ - name: Install dependencies
171
+ run: pip install -r requirements.txt
172
+ - name: Run benchmarks
173
+ uses: CodSpeedHQ/action@v3
174
+ with:
175
+ token: ${{ secrets.CODSPEED_TOKEN }}
176
+ run: pytest tests/ --codspeed
177
+ ```
@@ -0,0 +1,26 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ src/pytest_codspeed/__init__.py
6
+ src/pytest_codspeed/plugin.py
7
+ src/pytest_codspeed/py.typed
8
+ src/pytest_codspeed/utils.py
9
+ src/pytest_codspeed.egg-info/PKG-INFO
10
+ src/pytest_codspeed.egg-info/SOURCES.txt
11
+ src/pytest_codspeed.egg-info/dependency_links.txt
12
+ src/pytest_codspeed.egg-info/entry_points.txt
13
+ src/pytest_codspeed.egg-info/requires.txt
14
+ src/pytest_codspeed.egg-info/top_level.txt
15
+ src/pytest_codspeed/instruments/__init__.py
16
+ src/pytest_codspeed/instruments/walltime.py
17
+ src/pytest_codspeed/instruments/valgrind/__init__.py
18
+ src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py
19
+ src/pytest_codspeed/instruments/valgrind/_wrapper/build.py
20
+ src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c
21
+ src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h
22
+ src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.pyi
23
+ tests/test_pytest_plugin.py
24
+ tests/test_pytest_plugin_cpu_instrumentation.py
25
+ tests/test_pytest_plugin_walltime.py
26
+ tests/test_utils.py