python data_error ai_generated true

ValueError: duplicate parameter set with id 'case_1'

ID: python/pytest-parametrize-id-collision

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-07-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

Using the same ID for multiple parametrized cases without unique IDs.

generic

中文

为多个参数化用例使用相同的 ID,而没有唯一 ID。

Workarounds

  1. 99% success
    @pytest.mark.parametrize('arg', [1, 2], ids=['case_1', 'case_2'])
  2. 95% success
    def id_func(val):
        return f'case_{val}'
    @pytest.mark.parametrize('arg', [1, 2], ids=id_func)

Dead Ends

Common approaches that don't work:

  1. 40% fail

    Pytest will auto-generate IDs, but they may not be descriptive.

  2. 100% fail

    This still causes duplicate IDs.