Skip to content

Commit

Permalink
chore: add a test on the walltime instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Sep 17, 2024
1 parent 93c2222 commit 3c32d59
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
rev: v0.6.5
hooks:
- id: ruff
args: [--fix]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
]

[project.optional-dependencies]
lint = ["mypy ~= 1.3.0", "ruff ~= 0.3.3"]
lint = ["mypy ~= 1.11.2", "ruff ~= 0.6.5"]
compat = [
"pytest-benchmark ~= 4.0.0",
"pytest-xdist ~= 3.6.1",
Expand Down
12 changes: 9 additions & 3 deletions src/pytest_codspeed/instruments/walltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,20 @@ def measure(

def report(self, session: Session) -> None:
reporter = session.config.pluginmanager.get_plugin("terminalreporter")

if len(self.benchmarks) == 0:
reporter.write_sep(
"=",
f"{len(self.benchmarks)} benchmarked",
)
return
self._print_benchmark_table()
reporter.write_sep(
"=",
f"{len(self.benchmarks)} benchmarked",
)

if len(self.benchmarks) == 0:
return

def _print_benchmark_table(self) -> None:
table = Table(title="Benchmark Results")

table.add_column("Benchmark", justify="right", style="cyan", no_wrap=True)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_pytest_plugin_walltime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from conftest import run_pytest_codspeed_with_mode

from pytest_codspeed.instruments import MeasurementMode


def test_bench_enabled_header_with_perf(
pytester: pytest.Pytester,
) -> None:
pytester.copy_example("tests/examples/test_addition_fixture.py")
result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime)
result.stdout.fnmatch_lines(["*test_some_addition_performance*", "*1 benchmarked*"])

0 comments on commit 3c32d59

Please sign in to comment.