Bird
0
0

What is wrong with this pytest parametrize usage?

medium📝 Debug Q7 of 15
PyTest - Parametrize
What is wrong with this pytest parametrize usage?
@pytest.mark.parametrize('x,y', [(1, 2), (3, 4)], ids=['first'])
def test_add(x, y):
    assert x + y > 0
AThe parameter names should be a dictionary, not a string
BThe length of the ids list does not match the number of parameter sets
Cids should be a string, not a list
DThe test function must have only one argument when using ids
Step-by-Step Solution
Solution:
  1. Step 1: Check ids length

    There are two parameter sets but only one ID provided.
  2. Step 2: Understand requirement

    The ids list length must match the number of parameter tuples.
  3. Final Answer:

    The length of the ids list does not match the number of parameter sets -> Option B
  4. Quick Check:

    ids length must equal parameter sets count [OK]
Quick Trick: Match ids count to parameter tuples [OK]
Common Mistakes:
MISTAKES
  • Providing fewer IDs than parameter sets
  • Using wrong data types for parameter names
  • Assuming ids can be a single string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes