python
type_error
ai_generated
true
类型错误:ids必须是字符串列表或可调用对象,但得到的是整数
TypeError: ids must be a list of strings or callable, got int
ID: python/pytest-parametrize-ids-type
80%修复率
85%置信度
0证据数
2025-01-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。
English
pytest.parametrize的ids参数如果提供整数列表,pytest会报错,因为ids必须是字符串或可调用对象。
解决方案
-
95% 成功率
ids=lambda x: str(x)
-
90% 成功率
ids=['case1', 'case2']
无效尝试
常见但无效的做法:
-
50% 失败
转换后可能失去原始含义
-
40% 失败
不提供ids会生成默认ID,但可能不明确