Skip to content

Commit

Permalink
fix: fix display of parametrized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Sep 27, 2024
1 parent 2913baf commit 46fb608
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/pytest_codspeed/instruments/walltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING

from rich.console import Console
from rich.markup import escape
from rich.table import Table
from rich.text import Text

Expand Down Expand Up @@ -235,7 +236,7 @@ def _print_benchmark_table(self) -> None:
if rsd > 0.1:
rsd_text.stylize("red bold")
table.add_row(
bench.name,
escape(bench.name),
f"{bench.stats.min_ns/bench.stats.iter_per_round:,.0f}ns",
rsd_text,
f"{bench.stats.total_time:,.2f}s",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run_pytest_codspeed_with_mode(
]
if mode == MeasurementMode.WallTime:
# Run only 1 round to speed up the test times
csargs.extend(["--codspeed-warmup-time=0", "--codspeed-max-rounds=1"])
csargs.extend(["--codspeed-warmup-time=0", "--codspeed-max-rounds=2"])
return pytester.runpytest(
*csargs,
*args,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_pytest_plugin_walltime.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,28 @@ def test_bench_enabled_header_with_perf(
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*"])


def test_parametrization_naming(
pytester: pytest.Pytester,
) -> None:
pytester.makepyfile(
"""
import time, pytest
@pytest.mark.parametrize("inp", ["toto", 12, 58.3])
def test_my_stuff(benchmark, inp):
benchmark(lambda: time.sleep(0.01))
"""
)
result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime)
# Make sure the parametrization is not broken
print(result.outlines)
result.stdout.fnmatch_lines_random(
[
"*test_my_stuff[[]toto[]]*",
"*test_my_stuff[[]12[]]*",
"*test_my_stuff[[]58.3[]]*",
"*3 benchmarked*",
]
)

0 comments on commit 46fb608

Please sign in to comment.