Bird
0
0

What will be the output when running this pytest test?

medium📝 Predict Output Q13 of 15
PyTest - Parametrize
What will be the output when running this pytest test?
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
DFirst test fails, second test passes
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first test with inputs (1, 2)

    Sum is 1 + 2 = 3, assertion 3 == 3 passes.
  2. Step 2: Evaluate second test with inputs (3, 4)

    Sum is 3 + 4 = 7, assertion 7 == 3 fails.
  3. Final Answer:

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

    Check sums against 3 [OK]
Quick Trick: Calculate sums for each tuple and compare [OK]
Common Mistakes:
MISTAKES
  • Assuming all tests pass without checking values
  • Ignoring that assertion compares to fixed number 3
  • Confusing which test input causes failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes