Skip to content

Commit b1c2f93

Browse files
fix(test): normalize benchmark names without truncating param values
1 parent 83bb248 commit b1c2f93

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

scripts/check_benchmark_regression.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ class BenchmarkDataError(ValueError):
1515

1616

1717
def normalize_benchmark_name(name: str) -> str:
18-
"""Strip pytest node prefix so baselines match short or full benchmark names."""
19-
return str(name).rsplit("::", 1)[-1]
18+
"""Strip pytest file node prefix so baselines match short or full benchmark names."""
19+
text = str(name)
20+
if "::" not in text:
21+
return text
22+
prefix, _, suffix = text.partition("::")
23+
# Only strip module paths (…/test_foo.py::test_name); leave "::" inside [param::value] intact.
24+
if prefix.endswith(".py"):
25+
return suffix
26+
return text
2027

2128

2229
def load_results(results_path: str | Path) -> dict[str, float]:

tests/test_check_benchmark_regression.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ def test_normalize_benchmark_name_strips_module_prefix() -> None:
3737
assert normalize_benchmark_name("test_summary_cache_hit") == "test_summary_cache_hit"
3838

3939

40+
def test_normalize_benchmark_name_preserves_colons_in_param_values() -> None:
41+
short = "test_x[param::v]"
42+
full = f"tests/benchmarks/test_x.py::{short}"
43+
assert normalize_benchmark_name(short) == short
44+
assert normalize_benchmark_name(full) == short
45+
46+
4047
def test_load_results_normalizes_full_node_id(tmp_path) -> None:
4148
path = tmp_path / "results.json"
4249
_write_results(

0 commit comments

Comments
 (0)