python
data_error
ai_generated
true
ValueError: 2 parameters passed to 'test_add' but expected 1
ID: python/pytest-parametrize-arg-count-mismatch
80%Fix Rate
86%Confidence
0Evidence
2024-11-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
Root Cause
The @pytest.mark.parametrize decorator provides a number of arguments that does not match the test function's parameter list, causing a ValueError.
generic中文
@pytest.mark.parametrize 装饰器提供的参数数量与测试函数的参数列表不匹配,导致 ValueError。
Workarounds
-
95% success
Ensure the number of arguments in the parametrize decorator matches the test function's parameters. For example, if the test expects (a, b), use @pytest.mark.parametrize('a,b', [(1,2)]) -
80% success
Use a single argument with a tuple or list if the test function accepts one parameter that contains multiple values.
Dead Ends
Common approaches that don't work:
-
50% fail
Adding extra parameters to the test function without updating the parametrize decorator may fix the count but could break other tests.
-
70% fail
Removing arguments from the decorator without adjusting the test function leads to missing required parameters.