python data_error ai_generated true

SKIPPED [1] tests/test_math.py:12: 参数集 ['a', 'b'] 为空,函数 test_add

SKIPPED [1] tests/test_math.py:12: got empty parameter set ['a', 'b'], function test_add

ID: python/pytest-parametrize-empty-argvalues

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

版本兼容性

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

根因分析

`@pytest.mark.parametrize` 收到空的取值列表,因此测试被收集但跳过。通常是数据源(fixture、文件、计算列表)返回空。

English

`@pytest.mark.parametrize` received an empty list of values, so the test is collected but skipped. Often the data source (fixture, file, computed list) returned nothing.

generic

解决方案

  1. 90% 成功率
    Fail fast when the data source is unexpectedly empty:
    CASES = load_cases()
    if not CASES:
        pytest.fail('no cases loaded from fixtures/cases.json')
    @pytest.mark.parametrize('a,b', CASES)
  2. 85% 成功率
    Or use `pytest_generate_tests` to raise a clear error:
    def pytest_generate_tests(metafunc):
        if 'a' in metafunc.fixturenames:
            cases = load_cases()
            if not cases:
                pytest.fail('empty case set')
            metafunc.parametrize('a,b', cases)

无效尝试

常见但无效的做法:

  1. 80% 失败

    Already skipped; adding skip does not surface the underlying empty-data problem, which is usually a bug.

  2. 75% 失败

    Hides the real issue (data source empty) and reduces coverage silently.