python
config_error
ai_generated
true
ValueError: duplicate 'test_id' in parametrize
ID: python/pytest-parametrize-id-duplicate
80%Fix Rate
85%Confidence
0Evidence
2024-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Two or more parametrized cases have the same ID, either explicitly set via ids or generated automatically from identical parameter values.
generic中文
两个或多个参数化用例具有相同的 ID,要么通过 ids 显式设置,要么从相同的参数值自动生成。
Workarounds
-
95% success
@pytest.mark.parametrize('x', [1, 1], ids=['first', 'second']) def test_foo(x): ... -
90% success
def idfn(val): return f'val-{val}-{uuid.uuid4()}' @pytest.mark.parametrize('x', [1, 1], ids=idfn)
Dead Ends
Common approaches that don't work:
-
70% fail
If the parameter values are identical, pytest still generates duplicate IDs.
-
90% fail
The duplication is within the same test's parametrization, not across tests.