python
system_error
ai_generated
partial
pytest_benchmark.fixture.BenchmarkFixture: 基准 'test_sort' 失败: 5.21ms > 5.00ms(阈值)
pytest_benchmark.fixture.BenchmarkFixture: Benchmark 'test_sort' failed: 5.21ms > 5.00ms (threshold)
ID: python/pytest-benchmark-flaky-threshold
80%修复率
84%置信度
0证据数
2025-10-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.0.x | active | — | — | — |
根因分析
pytest-benchmark 的 --benchmark-max-time 或比较阈值对嘈杂的 CI 硬件过紧;几微秒的波动就会触发失败。
English
pytest-benchmark's --benchmark-max-time or comparison threshold is too tight for noisy CI hardware; a few microseconds of variance trips the gate.
解决方案
-
90% 成功率
pytest --benchmark-only \ --benchmark-compare=baseline \ --benchmark-compare-fail=median:15%
-
87% 成功率
pytest --benchmark-only --benchmark-disable-gc \ --benchmark-save=ci-$CI_RUN_ID # Compare offline; only fail on >25% median regression
无效尝试
常见但无效的做法:
-
80% 失败
Disables the benchmark entirely; performance regressions no longer surface.
-
70% 失败
Test ordering isn't the cause; hardware variance and CPU steal still produce flaky results.