python runtime_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2024-10-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.0 active

Root Cause

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

中文

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

Workarounds

  1. 95% success
    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% success
    pytest --benchmark-verbose tests/test_bench.py -s

Dead Ends

Common approaches that don't work:

  1. 85% fail

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

  2. 80% fail

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