python install_error ai_generated true

fixture 'benchmark' 未找到 可用 fixtures: cache, capfd, ...

fixture 'benchmark' not found available fixtures: cache, capfd, ...

ID: python/pytest-benchmark-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2025-02-24首次发现

版本兼容性

版本状态引入弃用备注
7.x active — — —
8.x active — — —

根因分析

未安装 pytest-benchmark,因此它提供的 'benchmark' fixture 不可用。常见于将 benchmark 测试复制到未安装开发依赖的仓库。

English

pytest-benchmark is not installed, so the 'benchmark' fixture it provides is unavailable. Common when copying benchmark tests into a repo without the dev dependency.

generic

解决方案

  1. 97% 成功率
    pip install pytest-benchmark
    
    # then
    def test_sort(benchmark):
        result = benchmark(sorted, list(range(1000)))
        assert result[0] == 0
  2. 90% 成功率
    import pytest
    
    pytest.importorskip('pytest_benchmark')
    
    def test_sort(benchmark):
        benchmark(sorted, list(range(1000)))

无效尝试

常见但无效的做法:

  1. 90% 失败

    Provides no timing, statistics, or comparison; the test gives false confidence.

  2. 70% 失败

    No integration with pytest reporting, no --benchmark-compare, and noisy CI output.