Skip to content

Commit 4a157bb

Browse files
Add a benchmark and the codspeed integration (#201)
* Add a benchmark and the codspeed integration * Only run the benchmarks on one strategy. Restore subprocess tests into test_tool.py file
1 parent ccf2441 commit 4a157bb

4 files changed

Lines changed: 112 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ jobs:
4040
- name: Run pytest
4141
uses: pavelzw/pytest-action@510c5e90c360a185039bea56ce8b3e7e51a16507 # v2.2.0
4242

43+
- name: Run benchmarks
44+
uses: CodSpeedHQ/action@513a19673a831f139e8717bf45ead67e47f00044 # v3.2.0
45+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' && matrix.resolution == 'highest'
46+
with:
47+
token: ${{ secrets.CODSPEED_TOKEN }}
48+
run: pytest --codspeed
49+
4350
strategy:
4451
matrix:
4552
os: [ubuntu-latest, macos-latest, windows-latest]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ test = [
5757
"coverage[toml]>=7.6.3",
5858
"gitpython>=3.1.43",
5959
"pytest>=8.3.2",
60+
"pytest-codspeed>=3.1.2",
6061
"pytest-cov>=5.0.0",
6162
"pytest-emoji>=0.2.0",
6263
"pytest-md>=0.2.0",

tests/usethis/_interface/test_tool.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from pathlib import Path
22

33
import pytest
4+
from typer.testing import CliRunner
45

56
from usethis._config import usethis_config
7+
from usethis._interface.tool import app
68
from usethis._subprocess import SubprocessFailedError, call_subprocess
79
from usethis._test import change_cwd
810

@@ -54,3 +56,27 @@ def test_cli(self, uv_init_dir: Path):
5456
call_subprocess(["usethis", "tool", "ruff"])
5557
else:
5658
call_subprocess(["usethis", "tool", "ruff", "--offline"])
59+
60+
61+
class TestPytest:
62+
def test_add(self, tmp_path: Path):
63+
# Act
64+
runner = CliRunner()
65+
with change_cwd(tmp_path):
66+
result = runner.invoke(app, ["pytest"])
67+
68+
# Assert
69+
assert result.exit_code == 0
70+
71+
72+
@pytest.mark.benchmark
73+
def test_several_tools_add_and_remove(tmp_path: Path):
74+
runner = CliRunner()
75+
with change_cwd(tmp_path):
76+
runner.invoke(app, ["pytest"])
77+
runner.invoke(app, ["ruff"])
78+
runner.invoke(app, ["deptry"])
79+
runner.invoke(app, ["pre-commit"])
80+
runner.invoke(app, ["ruff", "--remove"])
81+
runner.invoke(app, ["pyproject-fmt"])
82+
runner.invoke(app, ["pytest", "--remove"])

uv.lock

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

0 commit comments

Comments
 (0)