Bird
0
0

Find the issue in this test code:

medium📝 Debug Q7 of 15
PyTest - Parametrize
Find the issue in this test code:
@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', [3, 4])
def test_values(x, y):
assert x + y == 5
AParameter names in decorators do not match function arguments.
BTest will fail for some parameter combinations, but code is correct.
CMultiple parametrize decorators cause syntax error here.
DFunction should only accept one parameter when using multiple decorators.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter combinations

    Possible pairs: (1,3), (1,4), (2,3), (2,4).
  2. Step 2: Evaluate assertion for each pair

    Only (1,4) and (2,3) sum to 5; others fail assertion.
  3. Final Answer:

    Test will fail for some parameter combinations, but code is correct. -> Option B
  4. Quick Check:

    Assertion may fail but syntax is valid [OK]
Quick Trick: Passing parameters may cause assertion failures, not syntax errors [OK]
Common Mistakes:
MISTAKES
  • Assuming syntax error due to multiple decorators
  • Expecting all tests to pass
  • Confusing parameter names with function arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes