Bird
0
0

Given this pytest code, what will be the output?

medium📝 Predict Output Q5 of 15
PyTest - Basics and Setup
Given this pytest code, what will be the output?
import pytest

@pytest.mark.parametrize('x, y, expected', [(1, 2, 3), (2, 3, 5), (3, 5, 9)])
def test_add(x, y, expected):
    assert x + y == expected
AAll tests fail
BTwo tests pass, one test fails
CAll tests pass
DSyntax error due to parametrize
Step-by-Step Solution
Solution:
  1. Step 1: Check each parameter set

    Test cases: (1,2,3) passes, (2,3,5) passes, (3,5,9) fails because 3+5=8 not 9.
  2. Step 2: Determine overall test results

    Two tests pass, one test fails; pytest reports accordingly.
  3. Final Answer:

    Two tests pass, one test fails -> Option B
  4. Quick Check:

    Parametrized tests run all cases [OK]
Quick Trick: Check each param set carefully for expected results [OK]
Common Mistakes:
MISTAKES
  • Assuming all pass without checking expected values
  • Thinking parametrize causes syntax errors
  • Ignoring failed test case in output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes