Skip to content

Commit 46fb608

Browse files
committed
fix: fix display of parametrized tests
1 parent 2913baf commit 46fb608

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/pytest_codspeed/instruments/walltime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import TYPE_CHECKING
88

99
from rich.console import Console
10+
from rich.markup import escape
1011
from rich.table import Table
1112
from rich.text import Text
1213

@@ -235,7 +236,7 @@ def _print_benchmark_table(self) -> None:
235236
if rsd > 0.1:
236237
rsd_text.stylize("red bold")
237238
table.add_row(
238-
bench.name,
239+
escape(bench.name),
239240
f"{bench.stats.min_ns/bench.stats.iter_per_round:,.0f}ns",
240241
rsd_text,
241242
f"{bench.stats.total_time:,.2f}s",

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run_pytest_codspeed_with_mode(
7777
]
7878
if mode == MeasurementMode.WallTime:
7979
# Run only 1 round to speed up the test times
80-
csargs.extend(["--codspeed-warmup-time=0", "--codspeed-max-rounds=1"])
80+
csargs.extend(["--codspeed-warmup-time=0", "--codspeed-max-rounds=2"])
8181
return pytester.runpytest(
8282
*csargs,
8383
*args,

tests/test_pytest_plugin_walltime.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,28 @@ def test_bench_enabled_header_with_perf(
1010
pytester.copy_example("tests/examples/test_addition_fixture.py")
1111
result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime)
1212
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 commit comments

Comments
 (0)