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

Also available as: JSON · Markdown · 中文
80%Fix Rate
83%Confidence
0Evidence
2025-07-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.5 active

Root Cause

在@pytest.mark.parametrize中,ids参数传入了非字符串类型,如整数。

generic

中文

parametrize的ids参数类型错误,应为字符串列表或None。

Workarounds

  1. 100% success
    @pytest.mark.parametrize('param', [1, 2], ids=['one', 'two'])
  2. 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:

  1. 70% fail

    如果转换不当,可能生成重复id。

  2. 50% fail

    测试报告可读性下降。