Bird
0
0

What will be the output of this pytest test?

medium📝 Predict Output Q5 of 15
PyTest - Parametrize
What will be the output of this pytest test?
import pytest

@pytest.mark.parametrize('a,b', [(2, 3), (4, 5)])
def test_product(a, b):
    assert a * b == 6
AFirst test passes, second test fails
BBoth tests pass
CBoth tests fail
DTest skipped due to error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate each test case

    First: 2*3=6, assertion passes. Second: 4*5=20, assertion fails.
  2. Step 2: Summarize test results

    First test run passes, second test run fails due to assertion error.
  3. Final Answer:

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

    Check assertion for each param set separately [OK]
Quick Trick: Multiply params and compare for each test [OK]
Common Mistakes:
MISTAKES
  • Assuming all tests pass
  • Ignoring failure in second test
  • Thinking test is skipped

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes