Bird
0
0

What will happen when running this pytest code?

medium📝 Predict Output Q5 of 15
PyTest - Parametrize
What will happen when running this pytest code?
import pytest

@pytest.mark.parametrize('x,y', [(2, 2), (1, 3)])
def test_product(x, y):
    assert x * y == 4
ABoth test cases will pass.
BBoth test cases will fail.
CThe first test case will pass, the second will fail.
DThe first test case will fail, the second will pass.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze test cases

    First input: x=2, y=2, product=4, assertion: 4 == 4 (True). Second input: x=1, y=3, product=3, assertion: 3 == 4 (False).
  2. Step 2: Determine test results

    First test passes, second test fails.
  3. Final Answer:

    The first test case will pass, the second will fail. -> Option C
  4. Quick Check:

    Check product values against assertion [OK]
Quick Trick: Check each input pair's assertion result [OK]
Common Mistakes:
MISTAKES
  • Assuming all tests pass without checking values
  • Confusing multiplication with addition
  • Ignoring the assertion condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes