# ValueError: 名称数量 (2) 和值数量 (3) 必须匹配

- **ID:** `python/pytest-parametrize-valueerror`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

@pytest.mark.parametrize 装饰器中参数名称的数量与元组中的值的数量不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (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)])`
   ```
2. **** (90% 成功率)
   ```
   Use a dictionary for named parameters if the count is variable: `@pytest.mark.parametrize('test_input,expected', [{'test_input': 1, 'expected': 2}])`
   ```

## 无效尝试

- **** — This can lead to confusing test results and unused parameters that obscure the test's purpose. (85% 失败率)
- **** — This changes the structure of the parameterization, often causing type errors or unexpected test cases. (70% 失败率)
