python runtime_error ai_generated true

pytest_benchmark.fixture.BenchmarkFixture.NotEnoughTests:无法生成基准测试:未执行任何轮次(目标时间 0.0s,min_rounds 0)

pytest_benchmark.fixture.BenchmarkFixture.NotEnoughTests: Unable to produce a benchmark: no rounds executed (target time 0.0s, min_rounds 0)

ID: python/pytest-benchmark-no-results

其他格式: JSON · Markdown 中文 · English
80%修复率
83%置信度
0证据数
2024-10-05首次发现

版本兼容性

版本状态引入弃用备注
4.0 active

根因分析

被基准测试的函数在 benchmark 可调用对象内部引发了异常,或者校准设置(--benchmark-min-rounds=0 --benchmark-max-time=0)将运行压缩为 0 次迭代。函数内部的异常会被 pytest-benchmark 静默吞掉并报告为 NotEnoughTests。

English

The benchmarked function raised an exception inside the benchmark callable, or calibration settings (--benchmark-min-rounds=0 --benchmark-max-time=0) collapsed the run to zero iterations. Exception inside the function is silently swallowed by pytest-benchmark and reported as NotEnoughTests.

generic

解决方案

  1. 95% 成功率
    def test_parse_works():
        assert parse('1,2,3') == [1, 2, 3]
    
    def test_parse_bench(benchmark):
        result = benchmark(parse, '1,2,3')
        assert result == [1, 2, 3]
  2. 85% 成功率
    pytest --benchmark-verbose tests/test_bench.py -s

无效尝试

常见但无效的做法:

  1. 85% 失败

    If the function raises on every call, more rounds still fail; the exception is the root cause, not the round count.

  2. 80% 失败

    pytest-benchmark invokes the callable internally; wrapping the fixture call does not catch exceptions raised inside the benchmark loop.