Bird
0
0

What will be the output when running this pytest code?

medium📝 Predict Output Q13 of 15
PyTest - Parametrize
What will be the output when running this pytest code?
import pytest

@pytest.mark.parametrize('x,y', [(1,2), (3,4)])
def test_sum(x, y):
    assert x + y == 3
AFirst test passes, second test fails
BBoth tests fail
CBoth tests pass
DSyntax error during test collection
Step-by-Step Solution
Solution:
  1. Step 1: Analyze test cases and assertion

    Test runs twice: (1,2) and (3,4). Assertion checks if sum equals 3.
  2. Step 2: Evaluate each case

    1+2=3 passes; 3+4=7 fails assertion.
  3. Final Answer:

    First test passes, second test fails -> Option A
  4. Quick Check:

    Sum check true only for (1,2) [OK]
Quick Trick: Check each input pair sum against assertion [OK]
Common Mistakes:
MISTAKES
  • Assuming all tests pass without checking values
  • Confusing tuple unpacking in parametrize
  • Ignoring assertion logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes