Skip to content

Commit 0bd64af

Browse files
authored
Merge branch 'master' into add-mode
2 parents 3175622 + 192d881 commit 0bd64af

7 files changed

Lines changed: 69 additions & 44 deletions

File tree

.github/workflows/codspeed.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,42 @@ on:
88

99
env:
1010
PYTHON_VERSION: "3.12"
11+
SHARDS: 4
1112

1213
jobs:
13-
benchmarks-instrumentation:
14+
benchmarks:
1415
strategy:
1516
matrix:
16-
include:
17-
- mode: "instrumentation"
18-
runs-on: ubuntu-24.04
19-
- mode: "walltime"
20-
runs-on: codspeed-macro
17+
shard: [1, 2, 3, 4]
18+
mode: ["instrumentation", "walltime"]
2119

22-
name: Run ${{ matrix.mode }} benchmarks
23-
runs-on: ${{ matrix.runs-on }}
20+
name: "Run ${{ matrix.mode }} benchmarks (Shard #${{ matrix.shard }})"
21+
runs-on: ${{ matrix.mode == 'instrumentation' && 'ubuntu-24.04' || 'codspeed-macro' }}
2422
steps:
2523
- uses: actions/checkout@v4
2624
with:
2725
submodules: "recursive"
26+
- name: Install required-version defined in uv.toml
27+
uses: astral-sh/setup-uv@v5
2828
- uses: actions/setup-python@v2
2929
with:
3030
python-version: ${{ env.PYTHON_VERSION }}
3131
- name: Install local version of pytest-codspeed
3232
run: |
3333
sudo apt-get update
3434
sudo apt-get install valgrind -y
35-
pip install .
35+
uv sync --dev
3636
sudo apt-get remove valgrind -y
3737
- name: Run benchmarks
3838
uses: CodSpeedHQ/action@main
3939
with:
4040
mode: ${{ matrix.mode }}
41-
run: pytest tests/benchmarks/ --codspeed
41+
run: uv run pytest tests/benchmarks/ --codspeed --test-group=${{ matrix.shard }} --test-group-count=${{ env.SHARDS }}
4242
token: ${{ secrets.CODSPEED_TOKEN }}
43+
44+
all-checks:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- run: echo "All CI checks passed."
48+
needs:
49+
- benchmarks

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,24 @@ dependencies = [
3737
]
3838

3939
[project.optional-dependencies]
40-
lint = ["mypy ~= 1.11.2", "ruff ~= 0.11.12"]
4140
compat = [
4241
"pytest-benchmark ~= 5.0.0",
4342
"pytest-xdist ~= 3.6.1",
4443
# "pytest-speed>=0.3.5",
4544
]
46-
test = ["pytest ~= 7.0", "pytest-cov ~= 4.0.0"]
4745

4846
[tool.uv.sources]
4947
pytest-codspeed = { workspace = true }
5048

5149
[dependency-groups]
52-
dev = ["pytest-codspeed"]
50+
dev = [
51+
"pytest-codspeed",
52+
"mypy ~= 1.11.2",
53+
"ruff ~= 0.11.12",
54+
"pytest ~= 7.0",
55+
"pytest-cov ~= 4.0.0",
56+
"pytest-test-groups>=1.1.0",
57+
]
5358

5459
[project.entry-points]
5560
pytest11 = { codspeed = "pytest_codspeed.plugin" }

src/pytest_codspeed/instruments/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
from typing import Any, Callable, ClassVar, TypeVar
99

1010
import pytest
11+
from typing_extensions import ParamSpec
1112

1213
from pytest_codspeed.config import BenchmarkMarkerOptions, PedanticOptions
1314
from pytest_codspeed.plugin import CodSpeedConfig
1415

1516
T = TypeVar("T")
17+
P = ParamSpec("P")
1618

1719

1820
class Instrument(metaclass=ABCMeta):
@@ -30,9 +32,9 @@ def measure(
3032
marker_options: BenchmarkMarkerOptions,
3133
name: str,
3234
uri: str,
33-
fn: Callable[..., T],
34-
*args: tuple,
35-
**kwargs: dict[str, Any],
35+
fn: Callable[P, T],
36+
*args: P.args,
37+
**kwargs: P.kwargs,
3638
) -> T: ...
3739

3840
@abstractmethod

src/pytest_codspeed/instruments/valgrind.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pytest import Session
1515

1616
from pytest_codspeed.config import PedanticOptions
17-
from pytest_codspeed.instruments import T
17+
from pytest_codspeed.instruments import P, T
1818
from pytest_codspeed.plugin import BenchmarkMarkerOptions, CodSpeedConfig
1919

2020

@@ -52,9 +52,9 @@ def measure(
5252
marker_options: BenchmarkMarkerOptions,
5353
name: str,
5454
uri: str,
55-
fn: Callable[..., T],
56-
*args: tuple,
57-
**kwargs: dict[str, Any],
55+
fn: Callable[P, T],
56+
*args: P.args,
57+
**kwargs: P.kwargs,
5858
) -> T:
5959
self.benchmark_count += 1
6060

src/pytest_codspeed/instruments/walltime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pytest import Session
2525

2626
from pytest_codspeed.config import PedanticOptions
27-
from pytest_codspeed.instruments import T
27+
from pytest_codspeed.instruments import P, T
2828
from pytest_codspeed.plugin import BenchmarkMarkerOptions, CodSpeedConfig
2929

3030
DEFAULT_WARMUP_TIME_NS = 1_000_000_000
@@ -187,9 +187,9 @@ def measure(
187187
marker_options: BenchmarkMarkerOptions,
188188
name: str,
189189
uri: str,
190-
fn: Callable[..., T],
191-
*args: tuple,
192-
**kwargs: dict[str, Any],
190+
fn: Callable[P, T],
191+
*args: P.args,
192+
**kwargs: P.kwargs,
193193
) -> T:
194194
benchmark_config = BenchmarkConfig.from_codspeed_config_and_marker_data(
195195
self.config, marker_options

src/pytest_codspeed/plugin.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
from . import __version__
3131

3232
if TYPE_CHECKING:
33-
from typing import Any, Callable, TypeVar
33+
from typing import Any, Callable, ParamSpec, TypeVar
3434

3535
from pytest_codspeed.instruments import Instrument
3636

3737
T = TypeVar("T")
38+
P = ParamSpec("P")
3839

3940

4041
@pytest.hookimpl(trylast=True)
@@ -264,10 +265,10 @@ def wrap_runtest(
264265
plugin: CodSpeedPlugin,
265266
node: pytest.Item,
266267
config: pytest.Config,
267-
fn: Callable[..., T],
268-
) -> Callable[..., T]:
268+
fn: Callable[P, T],
269+
) -> Callable[P, T]:
269270
@functools.wraps(fn)
270-
def wrapped(*args: tuple, **kwargs: dict[str, Any]) -> T:
271+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
271272
return _measure(plugin, node, config, None, fn, args, kwargs)
272273

273274
return wrapped
@@ -328,9 +329,7 @@ def __init__(self, request: pytest.FixtureRequest):
328329
self._plugin = get_plugin(self._config)
329330
self._called = False
330331

331-
def __call__(
332-
self, target: Callable[..., T], *args: tuple, **kwargs: dict[str, Any]
333-
) -> T:
332+
def __call__(self, target: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
334333
if self._called:
335334
raise RuntimeError("The benchmark fixture can only be used once per test")
336335
self._called = True

uv.lock

Lines changed: 25 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)