python data_error ai_generated true

Failed: [pytest] 在 tests/test_parse.py:12 处的 'test_parse' 中参数集为空

Failed: [pytest] empty parameter set in 'test_parse' at tests/test_parse.py:12

ID: python/pytest-parametrize-empty-list

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

版本兼容性

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

根因分析

pytest.mark.parametrize 收到空列表作为 argvalues,pytest 报告空参数集并默认使测试失败(由 empty_parameter_set_mark 控制)。

English

pytest.mark.parametrize received an empty list for argvalues, so pytest reports an empty parameter set and fails the test by default (controlled by empty_parameter_set_mark).

generic

解决方案

  1. 90% 成功率
    # pytest.ini
    [pytest]
    empty_parameter_set_mark = skip
  2. 88% 成功率
    CASES = load_cases() or [pytest.param(None, marks=pytest.mark.skip('no cases'))]
    
    @pytest.mark.parametrize('case', CASES)
    def test_parse(case): ...

无效尝试

常见但无效的做法:

  1. 70% 失败

    Loses parameterization entirely; the test now runs once with undefined arguments and fails differently.

  2. 65% 失败

    Hides the fact that the data source is empty, which is often the actual bug worth surfacing.