# 类型错误：ids 必须是字符串列表或 None，但收到了 int

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

## 根因

@pytest.mark.parametrize 中的 'ids' 参数被提供为非字符串可迭代对象（例如整数列表），而不是字符串。

## 版本兼容性

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

## 解决方案

1. **Convert ids to a list of strings using str() or a lambda.** (95% 成功率)
   ```
   @pytest.mark.parametrize('arg', [1, 2], ids=[str(x) for x in [1, 2]])
   ```
2. **Use a lambda function to generate ids dynamically.** (90% 成功率)
   ```
   @pytest.mark.parametrize('arg', [1, 2], ids=lambda x: f'case_{x}')
   ```

## 无效尝试

- **Using list comprehension to convert ids to strings but forgetting to pass them** — If the conversion is not applied to the ids parameter, the error persists. (60% 失败率)
- **Omitting the ids parameter entirely** — Tests will run without custom IDs, but the error is avoided; however, test reports may be less readable. (50% 失败率)
