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
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).
解决方案
-
90% 成功率
# pytest.ini [pytest] empty_parameter_set_mark = skip
-
88% 成功率
CASES = load_cases() or [pytest.param(None, marks=pytest.mark.skip('no cases'))] @pytest.mark.parametrize('case', CASES) def test_parse(case): ...
无效尝试
常见但无效的做法:
-
70% 失败
Loses parameterization entirely; the test now runs once with undefined arguments and fails differently.
-
65% 失败
Hides the fact that the data source is empty, which is often the actual bug worth surfacing.