python
type_error
ai_generated
true
ValueError: 名称数量 (2) 和值数量 (3) 必须匹配
ValueError: The number of names (2) and values (3) must match
ID: python/pytest-parametrize-valueerror
80%修复率
85%置信度
0证据数
2024-07-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
@pytest.mark.parametrize 装饰器中参数名称的数量与元组中的值的数量不匹配。
English
The @pytest.mark.parametrize decorator has a mismatch between the number of parameter names and the number of values in a tuple.
解决方案
-
95% 成功率
Ensure each tuple in the values list has exactly the same number of elements as names: `@pytest.mark.parametrize('a,b', [(1,2), (3,4)])` -
90% 成功率
Use a dictionary for named parameters if the count is variable: `@pytest.mark.parametrize('test_input,expected', [{'test_input': 1, 'expected': 2}])`
无效尝试
常见但无效的做法:
-
85% 失败
This can lead to confusing test results and unused parameters that obscure the test's purpose.
-
70% 失败
This changes the structure of the parameterization, often causing type errors or unexpected test cases.