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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 90% 成功率
    pytest --benchmark-only \
      --benchmark-compare=baseline \
      --benchmark-compare-fail=median:15%
  2. 87% 成功率
    pytest --benchmark-only --benchmark-disable-gc \
      --benchmark-save=ci-$CI_RUN_ID
    # Compare offline; only fail on >25% median regression

无效尝试

常见但无效的做法:

  1. 80% 失败

    Disables the benchmark entirely; performance regressions no longer surface.

  2. 70% 失败

    Test ordering isn't the cause; hardware variance and CPU steal still produce flaky results.