# pytest_benchmark.fixture.BenchmarkFixture: 基准 'test_sort' 失败: 5.21ms > 5.00ms（阈值）

- **ID:** `python/pytest-benchmark-flaky-threshold`
- **领域:** python
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest-benchmark 的 --benchmark-max-time 或比较阈值对嘈杂的 CI 硬件过紧；几微秒的波动就会触发失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.0.x | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **** — Disables the benchmark entirely; performance regressions no longer surface. (80% 失败率)
- **** — Test ordering isn't the cause; hardware variance and CPU steal still produce flaky results. (70% 失败率)
