Bird
0
0

What will be the output when running this pytest code?

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

@pytest.mark.parametrize('num', [1, 2, 3])
def test_is_positive(num):
    assert num > 0
ATests fail for num=3
BAll tests fail
CTests fail for num=1
DAll tests pass
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the parameter values and assertion

    The test runs three times with num values 1, 2, and 3. The assertion checks if num > 0.
  2. Step 2: Check if assertion holds for all values

    Since 1, 2, and 3 are all greater than 0, all assertions pass.
  3. Final Answer:

    All tests pass -> Option D
  4. Quick Check:

    All nums > 0 = all pass [OK]
Quick Trick: Check assertion against all parameter values carefully [OK]
Common Mistakes:
MISTAKES
  • Assuming 1 is not greater than 0
  • Confusing fail and pass results
  • Ignoring all parameter values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes