pytest-codspeed 3.0.0b4__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.0b4 → pytest_codspeed-3.1.0}/PKG-INFO +21 -25
  2. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/README.md +4 -3
  3. {pytest_codspeed-3.0.0b4 → 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.0b4 → 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.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/plugin.py +12 -0
  10. pytest_codspeed-3.1.0/src/pytest_codspeed/py.typed +0 -0
  11. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/PKG-INFO +177 -0
  12. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/SOURCES.txt +26 -0
  13. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/dependency_links.txt +1 -0
  14. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/entry_points.txt +2 -0
  15. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/requires.txt +18 -0
  16. pytest_codspeed-3.1.0/src/pytest_codspeed.egg-info/top_level.txt +1 -0
  17. pytest_codspeed-3.1.0/tests/test_pytest_plugin.py +300 -0
  18. pytest_codspeed-3.1.0/tests/test_pytest_plugin_cpu_instrumentation.py +118 -0
  19. pytest_codspeed-3.1.0/tests/test_pytest_plugin_walltime.py +37 -0
  20. pytest_codspeed-3.1.0/tests/test_utils.py +34 -0
  21. pytest_codspeed-3.0.0b4/.gitignore +0 -166
  22. pytest_codspeed-3.0.0b4/src/pytest_codspeed/instruments/valgrind/_wrapper/.gitignore +0 -2
  23. pytest_codspeed-3.0.0b4/src/pytest_codspeed/instruments/valgrind/_wrapper/__init__.py +0 -40
  24. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/LICENSE +0 -0
  25. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/__init__.py +0 -0
  26. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/__init__.py +0 -0
  27. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.c +0 -0
  28. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.h +0 -0
  29. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/valgrind/_wrapper/wrapper.pyi +0 -0
  30. {pytest_codspeed-3.0.0b4 → pytest_codspeed-3.1.0}/src/pytest_codspeed/instruments/walltime.py +0 -0
  31. {pytest_codspeed-3.0.0b4 → 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.0b4
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.0b4"
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-b4"
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)
@@ -320,6 +320,18 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus):
320
320
  class BenchmarkFixture:
321
321
  """The fixture that can be used to benchmark a function."""
322
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
+
323
335
  def __init__(self, request: pytest.FixtureRequest):
324
336
  self.extra_info: dict = {}
325
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
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ codspeed = pytest_codspeed.plugin
@@ -0,0 +1,18 @@
1
+ cffi>=1.17.1
2
+ pytest>=3.8
3
+ rich>=13.8.1
4
+
5
+ [:python_version < "3.10"]
6
+ importlib-metadata>=8.5.0
7
+
8
+ [compat]
9
+ pytest-benchmark~=5.0.0
10
+ pytest-xdist~=3.6.1
11
+
12
+ [lint]
13
+ mypy~=1.11.2
14
+ ruff~=0.6.5
15
+
16
+ [test]
17
+ pytest~=7.0
18
+ pytest-cov~=4.0.0
@@ -0,0 +1 @@
1
+ pytest_codspeed
@@ -0,0 +1,300 @@
1
+ import pytest
2
+ from conftest import (
3
+ IS_PERF_TRAMPOLINE_SUPPORTED,
4
+ MeasurementMode,
5
+ run_pytest_codspeed_with_mode,
6
+ skip_with_perf_trampoline,
7
+ skip_without_pytest_benchmark,
8
+ skip_without_valgrind,
9
+ )
10
+
11
+
12
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
13
+ def test_plugin_enabled_with_kwargs(
14
+ pytester: pytest.Pytester, mode: MeasurementMode
15
+ ) -> None:
16
+ pytester.makepyfile(
17
+ """
18
+ def test_arg_kwarg_addition(benchmark):
19
+ def fn(arg, kwarg=None):
20
+ assert arg + kwarg == 40
21
+ benchmark(fn, 25, kwarg=15)
22
+ """
23
+ )
24
+ result = run_pytest_codspeed_with_mode(pytester, mode)
25
+ result.assert_outcomes(passed=1)
26
+
27
+
28
+ @skip_without_valgrind
29
+ @skip_with_perf_trampoline
30
+ def test_bench_enabled_header_without_perf(
31
+ pytester: pytest.Pytester, codspeed_env
32
+ ) -> None:
33
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
34
+ with codspeed_env():
35
+ result = pytester.runpytest()
36
+ result.stdout.fnmatch_lines(
37
+ ["codspeed: * (enabled, mode: instrumentation, callgraph: not supported)"]
38
+ )
39
+
40
+
41
+ @skip_without_valgrind
42
+ def test_plugin_enabled_by_env(pytester: pytest.Pytester, codspeed_env) -> None:
43
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
44
+ with codspeed_env():
45
+ result = pytester.runpytest()
46
+ result.stdout.fnmatch_lines(["*1 benchmarked*", "*1 passed*"])
47
+
48
+
49
+ @skip_without_valgrind
50
+ def test_plugin_enabled_and_env(pytester: pytest.Pytester, codspeed_env) -> None:
51
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
52
+ with codspeed_env():
53
+ result = pytester.runpytest("--codspeed")
54
+ result.stdout.fnmatch_lines(["*1 benchmarked*", "*1 passed*"])
55
+
56
+
57
+ @skip_without_valgrind
58
+ def test_plugin_enabled_and_env_bench_run_once(
59
+ pytester: pytest.Pytester, codspeed_env
60
+ ) -> None:
61
+ pytester.makepyfile(
62
+ """
63
+ import pytest
64
+
65
+ @pytest.mark.benchmark
66
+ def test_noisy_bench_marked():
67
+ print() # make sure noise is on its own line
68
+ print("I'm noisy marked!!!")
69
+ print()
70
+
71
+ def test_noisy_bench_fxt(benchmark):
72
+ @benchmark
73
+ def _():
74
+ print() # make sure noise is on its own line
75
+ print("I'm noisy fixtured!!!")
76
+ print()
77
+ """
78
+ )
79
+ EXPECTED_OUTPUT_COUNT = 2 if IS_PERF_TRAMPOLINE_SUPPORTED else 1
80
+ with codspeed_env():
81
+ run_result = pytester.runpytest("--codspeed", "-s")
82
+ print(run_result.stdout.str())
83
+ assert run_result.outlines.count("I'm noisy marked!!!") == EXPECTED_OUTPUT_COUNT
84
+ assert (
85
+ run_result.outlines.count("I'm noisy fixtured!!!") == EXPECTED_OUTPUT_COUNT
86
+ )
87
+
88
+
89
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
90
+ def test_plugin_enabled_and_env_bench_hierachy_called(
91
+ pytester: pytest.Pytester, mode: MeasurementMode
92
+ ) -> None:
93
+ pytester.makepyfile(
94
+ """
95
+ import pytest
96
+ import time
97
+
98
+ class TestGroup:
99
+ def setup_method(self):
100
+ print(); print("Setup called")
101
+
102
+ def teardown_method(self):
103
+ print(); print("Teardown called")
104
+
105
+ @pytest.mark.benchmark
106
+ def test_child(self):
107
+ time.sleep(0.1) # Avoids the test being too fast
108
+ print(); print("Test called")
109
+
110
+ """
111
+ )
112
+ result = run_pytest_codspeed_with_mode(pytester, mode, "-s")
113
+ result.stdout.fnmatch_lines(
114
+ [
115
+ "Setup called",
116
+ "Test called",
117
+ "Teardown called",
118
+ ]
119
+ )
120
+
121
+
122
+ def test_plugin_disabled(pytester: pytest.Pytester) -> None:
123
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
124
+ result = pytester.runpytest()
125
+ result.stdout.fnmatch_lines(["*1 passed*"])
126
+
127
+
128
+ @skip_without_valgrind
129
+ def test_plugin_enabled_nothing_to_benchmark(
130
+ pytester: pytest.Pytester, codspeed_env
131
+ ) -> None:
132
+ pytester.makepyfile(
133
+ """
134
+ def test_some_addition_performance():
135
+ return 1 + 1
136
+ """
137
+ )
138
+ with codspeed_env():
139
+ result = pytester.runpytest("--codspeed")
140
+ result.stdout.fnmatch_lines(["*0 benchmarked*", "*1 deselected*"])
141
+
142
+
143
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
144
+ def test_plugin_only_benchmark_collection(
145
+ pytester: pytest.Pytester, mode: MeasurementMode
146
+ ) -> None:
147
+ pytester.makepyfile(
148
+ """
149
+ import pytest
150
+
151
+ @pytest.mark.codspeed_benchmark
152
+ def test_some_addition_performance():
153
+ return 1 + 1
154
+
155
+ @pytest.mark.benchmark
156
+ def test_some_addition_performance_shorthand():
157
+ return 1 + 1
158
+
159
+ def test_some_wrapped_benchmark(benchmark):
160
+ @benchmark
161
+ def _():
162
+ hello = "hello"
163
+
164
+ def test_another_useless_thing():
165
+ assert True
166
+ """
167
+ )
168
+ collection_result = run_pytest_codspeed_with_mode(pytester, mode, "--collect-only")
169
+
170
+ collection_result.stdout.fnmatch_lines_random(
171
+ [
172
+ "*<Function test_some_addition_performance>*",
173
+ "*<Function test_some_addition_performance_shorthand>*",
174
+ "*<Function test_some_wrapped_benchmark>*",
175
+ ],
176
+ )
177
+ collection_result.assert_outcomes(
178
+ deselected=1,
179
+ )
180
+
181
+ collection_result = run_pytest_codspeed_with_mode(
182
+ pytester, mode, "--collect-only", "-k", "test_some_wrapped_benchmark"
183
+ )
184
+ collection_result.stdout.fnmatch_lines_random(
185
+ [
186
+ "*<Function test_some_wrapped_benchmark>*",
187
+ ],
188
+ )
189
+ collection_result.assert_outcomes(
190
+ deselected=3,
191
+ )
192
+
193
+
194
+ @skip_without_pytest_benchmark
195
+ def test_pytest_benchmark_compatibility(pytester: pytest.Pytester) -> None:
196
+ pytester.makepyfile(
197
+ """
198
+ def test_some_wrapped_benchmark(benchmark):
199
+ @benchmark
200
+ def _():
201
+ hello = "hello"
202
+ """
203
+ )
204
+ result = pytester.runpytest(
205
+ "--benchmark-only",
206
+ "--benchmark-max-time=0",
207
+ "--benchmark-warmup-iterations=1",
208
+ )
209
+ result.stdout.fnmatch_lines_random(
210
+ [
211
+ "*benchmark: 1 tests*",
212
+ "*Name*",
213
+ "*test_some_wrapped_benchmark*",
214
+ "*Legend:*",
215
+ "*Outliers:*",
216
+ "*OPS: Operations Per Second*",
217
+ "*Outliers:*",
218
+ "*1 passed*",
219
+ ]
220
+ )
221
+
222
+
223
+ def test_pytest_benchmark_extra_info(pytester: pytest.Pytester) -> None:
224
+ """https://pytest-benchmark.readthedocs.io/en/latest/usage.html#extra-info"""
225
+ pytester.makepyfile(
226
+ """
227
+ import time
228
+
229
+ def test_my_stuff(benchmark):
230
+ benchmark.extra_info['foo'] = 'bar'
231
+ benchmark(time.sleep, 0.02)
232
+ """
233
+ )
234
+ result = pytester.runpytest("--codspeed")
235
+ assert result.ret == 0, "the run should have succeeded"
236
+
237
+
238
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
239
+ def test_pytest_benchmark_return_value(
240
+ pytester: pytest.Pytester, mode: MeasurementMode
241
+ ) -> None:
242
+ pytester.makepyfile(
243
+ """
244
+ def calculate_something():
245
+ return 1 + 1
246
+
247
+ def test_my_stuff(benchmark):
248
+ value = benchmark(calculate_something)
249
+ assert value == 2
250
+ """
251
+ )
252
+ result = run_pytest_codspeed_with_mode(pytester, mode)
253
+ assert result.ret == 0, "the run should have succeeded"
254
+
255
+
256
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
257
+ def test_print(pytester: pytest.Pytester, mode: MeasurementMode) -> None:
258
+ """Test print statements are captured by pytest (i.e., not printed to terminal in
259
+ the middle of the progress bar) and only displayed after test run (on failures)."""
260
+ pytester.makepyfile(
261
+ """
262
+ import pytest, sys
263
+
264
+ @pytest.mark.benchmark
265
+ def test_print():
266
+ print("print to stdout")
267
+ print("print to stderr", file=sys.stderr)
268
+ """
269
+ )
270
+ result = run_pytest_codspeed_with_mode(pytester, mode)
271
+ assert result.ret == 0, "the run should have succeeded"
272
+ result.assert_outcomes(passed=1)
273
+ result.stdout.no_fnmatch_line("*print to stdout*")
274
+ result.stderr.no_fnmatch_line("*print to stderr*")
275
+
276
+
277
+ @pytest.mark.parametrize("mode", [*MeasurementMode])
278
+ def test_capsys(pytester: pytest.Pytester, mode: MeasurementMode):
279
+ """Test print statements are captured by capsys (i.e., not printed to terminal in
280
+ the middle of the progress bar) and can be inspected within test."""
281
+ pytester.makepyfile(
282
+ """
283
+ import pytest, sys
284
+
285
+ @pytest.mark.benchmark
286
+ def test_capsys(capsys):
287
+ print("print to stdout")
288
+ print("print to stderr", file=sys.stderr)
289
+
290
+ stdout, stderr = capsys.readouterr()
291
+
292
+ assert stdout == "print to stdout\\n"
293
+ assert stderr == "print to stderr\\n"
294
+ """
295
+ )
296
+ result = run_pytest_codspeed_with_mode(pytester, mode)
297
+ assert result.ret == 0, "the run should have succeeded"
298
+ result.assert_outcomes(passed=1)
299
+ result.stdout.no_fnmatch_line("*print to stdout*")
300
+ result.stderr.no_fnmatch_line("*print to stderr*")
@@ -0,0 +1,118 @@
1
+ import os
2
+
3
+ import pytest
4
+ from conftest import (
5
+ run_pytest_codspeed_with_mode,
6
+ skip_with_pytest_benchmark,
7
+ skip_without_perf_trampoline,
8
+ skip_without_pytest_xdist,
9
+ skip_without_valgrind,
10
+ )
11
+
12
+ from pytest_codspeed.instruments import MeasurementMode
13
+
14
+
15
+ @skip_without_valgrind
16
+ @skip_without_perf_trampoline
17
+ def test_bench_enabled_header_with_perf(
18
+ pytester: pytest.Pytester, codspeed_env
19
+ ) -> None:
20
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
21
+ with codspeed_env():
22
+ result = pytester.runpytest()
23
+ result.stdout.fnmatch_lines(
24
+ ["codspeed: * (enabled, mode: instrumentation, callgraph: enabled)"]
25
+ )
26
+
27
+
28
+ def test_plugin_enabled_cpu_instrumentation_without_env(
29
+ pytester: pytest.Pytester,
30
+ ) -> None:
31
+ pytester.makepyfile(
32
+ """
33
+ def test_some_addition_performance(benchmark):
34
+ @benchmark
35
+ def _():
36
+ return 1 + 1
37
+ """
38
+ )
39
+ result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.Instrumentation)
40
+ result.stdout.fnmatch_lines(
41
+ [
42
+ (
43
+ "*NOTICE: codspeed is enabled, but no "
44
+ "performance measurement will be made*"
45
+ ),
46
+ "*1 benchmark tested*",
47
+ "*1 passed*",
48
+ ]
49
+ )
50
+
51
+
52
+ @skip_without_valgrind
53
+ @skip_without_perf_trampoline
54
+ def test_perf_maps_generation(pytester: pytest.Pytester, codspeed_env) -> None:
55
+ pytester.makepyfile(
56
+ """
57
+ import pytest
58
+
59
+ @pytest.mark.benchmark
60
+ def test_some_addition_marked():
61
+ assert 1 + 1
62
+
63
+ def test_some_addition_fixtured(benchmark):
64
+ @benchmark
65
+ def fixtured_child():
66
+ assert 1 + 1
67
+ """
68
+ )
69
+ with codspeed_env():
70
+ result = pytester.runpytest("--codspeed")
71
+ result.stdout.fnmatch_lines(["*2 benchmarked*", "*2 passed*"])
72
+ current_pid = os.getpid()
73
+ perf_filepath = f"/tmp/perf-{current_pid}.map"
74
+ print(perf_filepath)
75
+
76
+ with open(perf_filepath) as perf_file:
77
+ lines = perf_file.readlines()
78
+ assert any(
79
+ "py::ValgrindInstrument.measure.<locals>.__codspeed_root_frame__" in line
80
+ for line in lines
81
+ ), "No root frame found in perf map"
82
+ assert any(
83
+ "py::test_some_addition_marked" in line for line in lines
84
+ ), "No marked test frame found in perf map"
85
+ assert any(
86
+ "py::test_some_addition_fixtured" in line for line in lines
87
+ ), "No fixtured test frame found in perf map"
88
+ assert any(
89
+ "py::test_some_addition_fixtured.<locals>.fixtured_child" in line
90
+ for line in lines
91
+ ), "No fixtured child test frame found in perf map"
92
+
93
+
94
+ @skip_without_valgrind
95
+ @skip_with_pytest_benchmark
96
+ @skip_without_pytest_xdist
97
+ def test_pytest_xdist_concurrency_compatibility(
98
+ pytester: pytest.Pytester, codspeed_env
99
+ ) -> None:
100
+ pytester.makepyfile(
101
+ """
102
+ import time, pytest
103
+
104
+ def do_something():
105
+ time.sleep(1)
106
+
107
+ @pytest.mark.parametrize("i", range(256))
108
+ def test_my_stuff(benchmark, i):
109
+ benchmark(do_something)
110
+ """
111
+ )
112
+ # Run the test multiple times to reduce the chance of a false positive
113
+ ITERATIONS = 5
114
+ for i in range(ITERATIONS):
115
+ with codspeed_env():
116
+ result = pytester.runpytest("--codspeed", "-n", "128")
117
+ assert result.ret == 0, "the run should have succeeded"
118
+ result.stdout.fnmatch_lines(["*256 passed*"])
@@ -0,0 +1,37 @@
1
+ import pytest
2
+ from conftest import run_pytest_codspeed_with_mode
3
+
4
+ from pytest_codspeed.instruments import MeasurementMode
5
+
6
+
7
+ def test_bench_enabled_header_with_perf(
8
+ pytester: pytest.Pytester,
9
+ ) -> None:
10
+ pytester.copy_example("tests/examples/test_addition_fixture.py")
11
+ result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime)
12
+ result.stdout.fnmatch_lines(["*test_some_addition_performance*", "*1 benchmarked*"])
13
+
14
+
15
+ def test_parametrization_naming(
16
+ pytester: pytest.Pytester,
17
+ ) -> None:
18
+ pytester.makepyfile(
19
+ """
20
+ import time, pytest
21
+
22
+ @pytest.mark.parametrize("inp", ["toto", 12, 58.3])
23
+ def test_my_stuff(benchmark, inp):
24
+ benchmark(lambda: time.sleep(0.01))
25
+ """
26
+ )
27
+ result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime)
28
+ # Make sure the parametrization is not broken
29
+ print(result.outlines)
30
+ result.stdout.fnmatch_lines_random(
31
+ [
32
+ "*test_my_stuff[[]toto[]]*",
33
+ "*test_my_stuff[[]12[]]*",
34
+ "*test_my_stuff[[]58.3[]]*",
35
+ "*3 benchmarked*",
36
+ ]
37
+ )
@@ -0,0 +1,34 @@
1
+ import tempfile
2
+ from contextlib import contextmanager
3
+ from pathlib import Path
4
+
5
+ from pytest_codspeed.utils import get_git_relative_path, get_git_relative_uri_and_name
6
+
7
+
8
+ @contextmanager
9
+ def TemporaryGitRepo():
10
+ with tempfile.TemporaryDirectory() as tmpdirname:
11
+ (Path(tmpdirname) / ".git").mkdir(parents=True)
12
+ yield tmpdirname
13
+
14
+
15
+ def test_get_git_relative_path_found():
16
+ with TemporaryGitRepo() as tmp_repo:
17
+ path = Path(tmp_repo) / "folder/nested_folder"
18
+ assert get_git_relative_path(path) == Path("folder/nested_folder")
19
+
20
+
21
+ def test_get_git_relative_path_not_found():
22
+ with tempfile.TemporaryDirectory() as tmp_dir:
23
+ path = Path(tmp_dir) / "folder"
24
+ assert get_git_relative_path(path) == path
25
+
26
+
27
+ def test_get_git_relative_uri():
28
+ with TemporaryGitRepo() as tmp_repo:
29
+ pytest_rootdir = Path(tmp_repo) / "pytest_root"
30
+ uri = "testing/test_excinfo.py::TestFormattedExcinfo::test_fn"
31
+ assert get_git_relative_uri_and_name(uri, pytest_rootdir) == (
32
+ "pytest_root/testing/test_excinfo.py::TestFormattedExcinfo::test_fn",
33
+ "TestFormattedExcinfo::test_fn",
34
+ )
@@ -1,166 +0,0 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # C extensions
7
- *.so
8
-
9
- # Distribution / packaging
10
- .Python
11
- build/
12
- develop-eggs/
13
- dist/
14
- downloads/
15
- eggs/
16
- .eggs/
17
- lib/
18
- lib64/
19
- parts/
20
- sdist/
21
- var/
22
- wheels/
23
- share/python-wheels/
24
- *.egg-info/
25
- .installed.cfg
26
- *.egg
27
- MANIFEST
28
-
29
- # PyInstaller
30
- # Usually these files are written by a python script from a template
31
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
- *.manifest
33
- *.spec
34
-
35
- # Installer logs
36
- pip-log.txt
37
- pip-delete-this-directory.txt
38
-
39
- # Unit test / coverage reports
40
- htmlcov/
41
- .tox/
42
- .nox/
43
- .coverage
44
- .coverage.*
45
- .cache
46
- nosetests.xml
47
- coverage.xml
48
- *.cover
49
- *.py,cover
50
- .hypothesis/
51
- .pytest_cache/
52
- cover/
53
-
54
- # Translations
55
- *.mo
56
- *.pot
57
-
58
- # Django stuff:
59
- *.log
60
- local_settings.py
61
- db.sqlite3
62
- db.sqlite3-journal
63
-
64
- # Flask stuff:
65
- instance/
66
- .webassets-cache
67
-
68
- # Scrapy stuff:
69
- .scrapy
70
-
71
- # Sphinx documentation
72
- docs/_build/
73
-
74
- # PyBuilder
75
- .pybuilder/
76
- target/
77
-
78
- # Jupyter Notebook
79
- .ipynb_checkpoints
80
-
81
- # IPython
82
- profile_default/
83
- ipython_config.py
84
-
85
- # pyenv
86
- # For a library or package, you might want to ignore these files since the code is
87
- # intended to run in multiple environments; otherwise, check them in:
88
- # .python-version
89
-
90
- # pipenv
91
- # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
- # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
- # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
- # install all needed dependencies.
95
- #Pipfile.lock
96
-
97
- # poetry
98
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
- # This is especially recommended for binary packages to ensure reproducibility, and is more
100
- # commonly ignored for libraries.
101
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
- #poetry.lock
103
-
104
- # pdm
105
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
- #pdm.lock
107
- # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
- # in version control.
109
- # https://pdm.fming.dev/#use-with-ide
110
- .pdm.toml
111
-
112
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
- __pypackages__/
114
-
115
- # Celery stuff
116
- celerybeat-schedule
117
- celerybeat.pid
118
-
119
- # SageMath parsed files
120
- *.sage.py
121
-
122
- # Environments
123
- .env
124
- .venv
125
- env/
126
- venv/
127
- ENV/
128
- env.bak/
129
- venv.bak/
130
-
131
- # Spyder project settings
132
- .spyderproject
133
- .spyproject
134
-
135
- # Rope project settings
136
- .ropeproject
137
-
138
- # mkdocs documentation
139
- /site
140
-
141
- # mypy
142
- .mypy_cache/
143
- .dmypy.json
144
- dmypy.json
145
-
146
- # Pyre type checker
147
- .pyre/
148
-
149
- # pytype static type analyzer
150
- .pytype/
151
-
152
- # Cython debug symbols
153
- cython_debug/
154
-
155
- # PyCharm
156
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
- # and can be added to the global gitignore or merged into this file. For a more nuclear
159
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
- #.idea/
161
-
162
- .venvubuntu
163
- .python-version
164
- *.o
165
-
166
- .codspeed
@@ -1,2 +0,0 @@
1
- dist_callgrind_wrapper.*
2
- build.lock
@@ -1,40 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- from typing import TYPE_CHECKING
5
-
6
- from cffi import FFI # type: ignore
7
- from filelock import FileLock
8
-
9
- if TYPE_CHECKING:
10
- from .wrapper import lib as LibType
11
-
12
- _wrapper_dir = os.path.dirname(os.path.abspath(__file__))
13
-
14
-
15
- def _get_ffi():
16
- ffi = FFI()
17
- with open(f"{_wrapper_dir}/wrapper.h") as f:
18
- ffi.cdef(f.read())
19
- ffi.set_source(
20
- "dist_callgrind_wrapper",
21
- '#include "wrapper.h"',
22
- sources=["wrapper.c"],
23
- )
24
- return ffi
25
-
26
-
27
- def get_lib() -> LibType:
28
- try:
29
- ffi = _get_ffi()
30
- build_lock = FileLock(f"{_wrapper_dir}/build.lock")
31
- with build_lock:
32
- ffi.compile(
33
- target="dist_callgrind_wrapper.*",
34
- tmpdir=_wrapper_dir,
35
- )
36
- from .dist_callgrind_wrapper import lib # type: ignore
37
-
38
- return lib
39
- except Exception as e:
40
- raise Exception("Failed to compile the wrapper") from e