python
type_error
ai_generated
true
TypeError: ids must be a list of strings or None, got <class 'int'>
ID: python/pytest-parametrize-ids-none
80%Fix Rate
83%Confidence
0Evidence
2025-07-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.5 | active | — | — | — |
Root Cause
在@pytest.mark.parametrize中,ids参数传入了非字符串类型,如整数。
generic中文
parametrize的ids参数类型错误,应为字符串列表或None。
Workarounds
-
100% success
@pytest.mark.parametrize('param', [1, 2], ids=['one', 'two']) -
95% success
def id_fn(val): return f'param_{val}' @pytest.mark.parametrize('param', [1, 2], ids=id_fn)
Dead Ends
Common approaches that don't work:
-
70% fail
如果转换不当,可能生成重复id。
-
50% fail
测试报告可读性下降。